James Hancock
asked on
Can Java Image objects be paused or frames extracted?
I have animated GIF's in my game.
I'd like to be able to display one of the frames in the GIF, done in code, without making individual GIF files for the desired image / single frame.
Since I already have the image loaded (in the animation) can I make a new Image Object from one of the animation frames?
If not a new image object, can I tell an Image object to pause() ?
I'd like to be able to display one of the frames in the GIF, done in code, without making individual GIF files for the desired image / single frame.
Since I already have the image loaded (in the animation) can I make a new Image Object from one of the animation frames?
If not a new image object, can I tell an Image object to pause() ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
See the code above for how to make individual images without writing them to files - they are of course forst extracted
and then written to files.
and then written to files.
ASKER
How can I change the last for loop to return the k-th image as an Image object, not as a bufferedImage ?
Can I "cast" a bufferedimage to an Image Object?
I don't need to write it to an external file, I need it loaded in to an Image Object right away
// in last for loop above
if (i==k) return Toolkit.getDefaultToolkit( ).createIm age(buffer edImage.ge tSource()) ;
?
Will that be, as if, extracting a paused image?
Can I "cast" a bufferedimage to an Image Object?
I don't need to write it to an external file, I need it loaded in to an Image Object right away
// in last for loop above
if (i==k) return Toolkit.getDefaultToolkit(
?
Will that be, as if, extracting a paused image?
This gives example from buffered image to image drawing
http://www.javalobby.org/articles/ultimate-image/
http://www.javalobby.org/articles/ultimate-image/
ASKER
It looks like that is only relevant for BufferredImage objects. not plain Image objects
Mine are regular awt Image objects
Is there a bufferedimage extraction capability from an Image object?
and also, then buffered image back to Image ?
Cause, then I can use that code, no problem
Mine are regular awt Image objects
Is there a bufferedimage extraction capability from an Image object?
and also, then buffered image back to Image ?
Cause, then I can use that code, no problem
I think this converts Image to BufferedImage:
http://www.java2s.com/Code/Java/2D-Graphics-GUI/ConvertjavaawtimageBufferedImagetojavaawtImage.htm
and this is drawing image from BufferedImage from that link above:
BufferedImage loadImg = ImageUtil.loadImage("C:/Images/duke.gif");
frame.setBounds(0, 0, loadImg.getWidth(), loadImg.getHeight());
// Set the panel visible and add it to the frame
frame.setVisible(true);
// Get the surfaces Graphics object
Graphics2D g = (Graphics2D)frame.getRootPane().getGraphics();
// Now draw the image
g.drawImage(loadImg, null, 0, 0);
So from animated gif you can either write it to a file or
darrw it on java component, doesn't that cover your needs?
ASKER
for the last 3 lines, I can just use the getgraphics from my Image object, I guess.
Game over, no worrying about buffered image conversion or components?
Game over, no worrying about buffered image conversion or components?
I think so, irt seems you should be able to do it both ways
ASKER
Could you please give me a bit of text on that page to find the conversion of bufferedimage to image? - section? (ultimate image thing)
> give me a bit of text on that page
Sorry, don't understand whivh page you mean.
Please, explain.
ASKER
I can't find the exact code lines that do the conversions.
May I have a hint as to its place ( If I can search for text in that area, it would be good)
May I have a hint as to its place ( If I can search for text in that area, it would be good)
the code in
ID:36951481
allows you to show image on your java component.
Try how it works.
I didn't try but hope it does work.
So you can write graphics file form BufferedImage, you can show it ion Java component.
What other needs do you have?
BufferedImage is actually subclass of Image.
Image is abstract class. So you cannot talke about conversion of BufferedImgae to Image.
BufferedImage IS Image
see http://download.oracle.com/javase/1.4.2/docs/api/java/awt/image/BufferedImage.html
Image is abstract class. So you cannot talke about conversion of BufferedImgae to Image.
BufferedImage IS Image
see http://download.oracle.com/javase/1.4.2/docs/api/java/awt/image/BufferedImage.html
ASKER
thx
You are always welcome.
http://www.java2s.com/Tutorial/Java/0419__PDF/GetFramefromAnimatedGif.htm
Open in new window