J2ME GIF 解码器(支持动画)
来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-01 21:32 点击:次
Displaying GIF Images on J2ME Mobile Phones
J2SE GIF Source
J2SE GIF Source
第一篇文章讲解比较详细,曾被多次转载。而第二篇则是GIF编解码器的J2SE源代码。
我正是在参考了以上文章之后,才开始对该代码展开移植。包括测试也就用了半天时间。感兴趣的朋友最好自己动手试一试。有麻烦的话,可以联系我。
下面先把J2ME版本的GIF解码器源代码公布如下。稍后提供编码器的代码(工作比较忙,抱歉)。
import java.io.InputStream;
import java.util.Vector;
import javax.microedition.lcdui.Image;
/**
* Class GifDecoder - Decodes a GIF file into one or more frames. <br>
*
* <pre>
* Example:
* GifDecoder d = new GifDecoder();
* d.read("sample.gif");
* int n = d.getFrameCount();
* for (int i = 0; i < n; i++) {
* BufferedImage frame = d.getFrame(i); // frame i
* int t = d.getDelay(i); // display duration of frame in milliseconds
* // do something with frame
* }
* </pre>
*
* No copyright asserted on the source code of this class. May be used for any
* purpose, however, refer to the Unisys LZW patent for any additional
* restrictions. Please forward any corrections to kweiner@fmsware.com.
*
* @author Kevin Weiner, FM Software; LZW decoder adapted from John Cristy's
* ImageMagick.
* @version 1.03 November 2003
*
*/
* Class GifDecoder - Decodes a GIF file into one or more frames. <br>
*
* <pre>
* Example:
* GifDecoder d = new GifDecoder();
* d.read("sample.gif");
* int n = d.getFrameCount();
* for (int i = 0; i < n; i++) {
* BufferedImage frame = d.getFrame(i); // frame i
* int t = d.getDelay(i); // display duration of frame in milliseconds
* // do something with frame
* }
* </pre>
*
* No copyright asserted on the source code of this class. May be used for any
* purpose, however, refer to the Unisys LZW patent for any additional
* restrictions. Please forward any corrections to kweiner@fmsware.com.
*
* @author Kevin Weiner, FM Software; LZW decoder adapted from John Cristy's
* ImageMagick.
* @version 1.03 November 2003
*
*/
public class GifDecoder {
/**
* File read status: No errors.
*/
public static final int STATUS_OK = 0;
* File read status: No errors.
*/
public static final int STATUS_OK = 0;
/**
* File read status: Error decoding file (may be partially decoded)
*/
public static final int STATUS_FORMAT_ERROR = 1;
* File read status: Error decoding file (may be partially decoded)
*/
public static final int STATUS_FORMAT_ERROR = 1;
/**
* File read status: Unable to open source.
*/
public static final int STATUS_OPEN_ERROR = 2;
* File read status: Unable to open source.
*/
public static final int STATUS_OPEN_ERROR = 2;
protected InputStream in;
protected int status;
protected int status;
protected int width; // full image width
protected int height; // full image height
protected boolean gctFlag; // global color table used
protected int gctSize; // size of global color table
protected int loopCount = 1; // iterations; 0 = repeat forever
protected int height; // full image height
protected boolean gctFlag; // global color table used
protected int gctSize; // size of global color table
protected int loopCount = 1; // iterations; 0 = repeat forever
protected int[] gct; // global color table
protected int[] lct; // local color table
protected int[] act; // active color table
protected int[] lct; // local color table
protected int[] act; // active color table
protected int bgIndex; // background color index
protected int bgColor; // background color
protected int lastBgColor; // previous bg color
protected int pixelAspect; // pixel aspect ratio
protected int bgColor; // background color
protected int lastBgColor; // previous bg color
protected int pixelAspect; // pixel aspect ratio
protected boolean lctFlag; // local color table flag
protected boolean interlace; // interlace flag
protected int lctSize; // local color table size
protected boolean interlace; // interlace flag
protected int lctSize; // local color table size
protected int ix, iy, iw, ih; // current image rectangle
protected int lrx, lry, lrw, lrh;
protected Image image; // current frame
protected Image lastImage; // previous frame
protected int lrx, lry, lrw, lrh;
protected Image image; // current frame
protected Image lastImage; // previous frame
protected byte[] block = new byte[256]; // current data block
 
 
相关新闻>>
- 发表评论
-
- 最新评论 更多>>