0

I'm developing AppEngine application. One of it's features is splitting an animated .gif image into separate frames. I've searched a lot to find the way how to do it and finally found the solution. Unfortunately the solution is based on ImageReader and I cant use it on the server, because:

javax.imageio.ImageReader is not supported by Google App Engine's Java runtime environment

Are there any other ways to decode GIF-image without this class?

tibtof
  • 7,857
  • 1
  • 32
  • 49
  • Um, did you Google "java gif decode"? – Jim Garrison Jun 12 '12 at 21:56
  • Yep, I did. First several links are about Gif4J library, but this library is non-free. Among other links I've found the solution with ImageReader which doesn't work for me as I mentioned in the question. –  Jun 12 '12 at 22:04

1 Answers1

0

First some thing about frame itself. There are two implications about splitting an animated .gif image into separate frames. 1) Literally, a frame is a frame in the sense of an animated GIF. The problem is frames which constitute an animated GIF image are related. The disposal method of an animated GIF dictates what to do with the previous frame when drawing the current frame. You can override it; fill with background color before drawing the new frame, or you can do whatever you think appropriate before drawing the new frame. If you think the above situation is complicated, what about transparency of frames? logical position to draw each frames?

If we go along this road, there is no need to use a dedicated ImageReader, just read relevant parts of the image and copy each frame data, save it along with a header and color palette. The consequence is: the resulting image might look weird and meaningless. Look at the example below:

The first frame frame0

The second frame frame1

And the original original

You can see the second frame doesn't look so good. The truth is, the second frame is a transparent one which build on top of the first frame (this animated GIF only contains 2 frames). You are expect to see through the second frame and altogether, they make an animation.

Now let's see what the second implication of splitting an animated .gif image into separate frames. 2) In this case, the frame is a actually is a composite which builds upon the previous frames and which is what we are seeing when viewing an animated GIF. In order to achieve this, we have to take into effect the history of the frame loop, the logical position of each frame, and the transparency of the frames themselves.

Let's see what we get now:

The first frame frame0

The second frame frame1

Now the first frame is the same as in the first situation, but the second frame is constructed on top of the first one and it's not transparent anymore.

In the second case, we do have to decode and encode the frames to achieve the desired result. Besides looking nice, another good thing about this is you can save the resulting images in any format the encoder support.

The examples in this post are generated by the GIF related part of iCafe

dragon66
  • 2,645
  • 2
  • 21
  • 43