R
Rhino
I've started working with the ImageIO but there is something I don't see in
the API Guide or the API.
Basically, I would like to write code that uses ImageIO classes to get all
of the images comprising a given animated GIF and then view them as an
animation. I already have all the code to do this via NON-ImageIO classes
but I'm not clear on what I need to do if I use ImageIO classes instead.
In my existing animated GIF viewer, I simply execute this code and the
entire GIF with all of its images is read and loaded into a MediaTracker;
all I need to give it is the URL that points to the animated GIF:
animatedGif = Toolkit.getDefaultToolkit().getImage(animatedGifUrl);
MediaTracker mediaTracker = new MediaTracker(this);
mediaTracker.addImage(animatedGif, 0);
try {
mediaTracker.waitForAll();
} catch (InterruptedException i_excp) {
//error handling
}
My paint() method simply does the following:
g.drawImage(animatedGif, 0, 0, this);
What happens if I want to use the ImageIO classes? Do I need read and load
each image in the GIF separately? Or can I suck the entire GIF with all of
its frames into the MediaTracker in a single gulp like in my old code?
Does anyone have a code fragment that illustrates what I need to do? I could
figure this out by trial and error but I thought I'd try to "work smarter,
not harder" for a change
Also, for bonus points, can anyone tell me exactly why it is better to do
this via ImageIO classes than the way I did it before? In other words, what
are the benefits of ImageIO classes over older approaches? Both approaches
involve standard Java classes so I'm guessing ImageIO classes have better
performance?
the API Guide or the API.
Basically, I would like to write code that uses ImageIO classes to get all
of the images comprising a given animated GIF and then view them as an
animation. I already have all the code to do this via NON-ImageIO classes
but I'm not clear on what I need to do if I use ImageIO classes instead.
In my existing animated GIF viewer, I simply execute this code and the
entire GIF with all of its images is read and loaded into a MediaTracker;
all I need to give it is the URL that points to the animated GIF:
animatedGif = Toolkit.getDefaultToolkit().getImage(animatedGifUrl);
MediaTracker mediaTracker = new MediaTracker(this);
mediaTracker.addImage(animatedGif, 0);
try {
mediaTracker.waitForAll();
} catch (InterruptedException i_excp) {
//error handling
}
My paint() method simply does the following:
g.drawImage(animatedGif, 0, 0, this);
What happens if I want to use the ImageIO classes? Do I need read and load
each image in the GIF separately? Or can I suck the entire GIF with all of
its frames into the MediaTracker in a single gulp like in my old code?
Does anyone have a code fragment that illustrates what I need to do? I could
figure this out by trial and error but I thought I'd try to "work smarter,
not harder" for a change
Also, for bonus points, can anyone tell me exactly why it is better to do
this via ImageIO classes than the way I did it before? In other words, what
are the benefits of ImageIO classes over older approaches? Both approaches
involve standard Java classes so I'm guessing ImageIO classes have better
performance?