Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get first frame of gif image

 
kavin clain
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to get first frame of gif image... ?

Is there any way to save gif as jpeg image?
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic