Java:在没有ImageReader的情况下从动画GIF获取帧 [英] Java: get frames from animated GIF without ImageReader

查看:1803
本文介绍了Java:在没有ImageReader的情况下从动画GIF获取帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发AppEngine应用程序.它的功能之一是将动画的.gif图像拆分为单独的帧.我进行了很多搜索,以找到方法,最后找到了解决方案.不幸的是,该解决方案基于ImageReader,我不能在服务器上使用它,因为:

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:

Google App Engine的Java不支持

javax.imageio.ImageReader 运行时环境

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

如果没有此类,还有其他方法可以解码GIF图像吗?

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

推荐答案

首先要了解框架本身.将动画的.gif图像拆分为单独的帧有两个含义. 1)从字面上看,框架是指动画GIF的框架.问题在于构成动画GIF图像的帧是相关的.动画GIF的处理方法规定了在绘制当前帧时如何处理前一帧.您可以覆盖它;在绘制新框架之前填充背景色,或者在绘制新框架之前可以做任何您认为合适的事情.如果您认为上述情况很复杂,那么框架的透明度又如何呢?绘制每帧的逻辑位置?

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?

如果我们沿着这条路走,则无需使用专用的ImageReader,只需读取图像的相关部分并复制每个帧数据,然后将其与页眉和调色板一起保存即可.结果是:生成的图像可能看起来很奇怪且毫无意义.看下面的例子:

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:

第一帧

第二帧

原始的

您可以看到第二帧看起来不太好.事实是,第二帧是透明的,它建立在第一帧的顶部(此动画GIF仅包含2帧).您应该可以看穿第二帧,并且它们一起制作了动画.

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.

现在,让我们看看将动画的.gif图像拆分为单独的帧的第二个含义. 2)在这种情况下,该帧实际上是一个基于先前帧的合成,这就是我们在查看动画GIF时看到的内容.为了实现这一点,我们必须使帧循环的历史记录,每个帧的逻辑位置以及帧本身的透明性生效.

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:

第一帧

第二帧

现在,第一个框架与第一种情况相同,但是第二个框架构造在第一个框架的顶部,并且不再透明.

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.

本文中的示例由 iCafe

这篇关于Java:在没有ImageReader的情况下从动画GIF获取帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆