Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Assigning a GIF/JPG to Image object

 
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)?
 
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.
 
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 ]
 
Hot dog! An advertiser loves us THIS much:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic