aspose file tools*
The moose likes Java in General and the fly likes Get first frame of gif image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Get first frame of gif image" Watch "Get first frame of gif image" New topic
Author

Get first frame of gif image

kavin clain
Ranch Hand

Joined: Jan 19, 2010
Posts: 68
How to get first frame of gif image... ?

Is there any way to save gif as jpeg image?
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
The javax.imageio.ImageIO class has methods to read and write various bitmap image formats. With its help, reading a GIF and writing it to a JPEG could be as little as two lines of code.

I would imagine that using ImageIO to read an animated GIF would cause the first frame of it to be read (the class has no concept of animations, just single images).
kavin clain
Ranch Hand

Joined: Jan 19, 2010
Posts: 68

The javax.imageio.ImageIO class has methods to read and write various bitmap image formats. With its help, reading a GIF and writing it to a JPEG could be as little as two lines of code.


Thank you Lester. could you please provide me the code.

I used below code but failed. The saved file is of 0 byte.

Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
The first line of code would read the image into a BufferedImage object, and the second line writes that object to a file. You should be able to figure out the rest pretty quickly by reading through javadocs of the ImageIO class.

Telling us that a particular statement didn't work as you expected it to work doesn't give us much to work with if we don't know the values of the involved variables, and maybe some contextual code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get first frame of gif image