Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assigning a GIF/JPG to Image object

 
donepudi madhu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me how to assign a GIF/JPG(in my directory)to an Image object(or BufferedImage object)?
 
Chad McGowan
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the Java Advanced Imaging API.
JAI
There should be some tutorials and/or examples on how to encode and decode different image formats.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
donepudi_madhu,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Displaying GIFs is pretty easy. For example...
Download the big moose graphic in the upper left corner of this page and save it as "moosebig.gif" in the same directory where you'll create a Java applet. In this directory, create a text file named FooApplet.java and edit it to have these contents:Compile the .java file. Now create a new text document and name it MyApplet.html. Edit it to have these contents:Save the html file and view it using the appletviewer (appletviewer MyApplet.html) or with a web browser.
 
donepudi madhu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir, very thankfull for your reply. It worked well in Applets.If I try it in Swing, it says that getDocumentBase is not found.Can you please tell me how to do that?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gladly. But do me a favor first and please change your display name as requested.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
Take a look at the methods of java.awt.Toolkit.
Image image = java.awt.Toolkit.getDefaultToolkit().getImage( String );
[ September 27, 2002: Message edited by: Dirk Schreckmann ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic