background image

Java 问题:J2ME 中的 GIF 处理类

发一个 GIF 处理的类,可以减少图片资源,不需要太多的 png

 

 

用法如下:

private GIFDecode gifd;
private int ind;
private int gifCount;
private Image frame;
void initGIF() {
gifd = new GIFDecode();
gifd.read(this.getClass().getResourceAsStream("/ar.gif"));//载入 gif

 

图片

ind = 0;
gifCount = gifd.getFrameCount();//

 

获得帧数

System.out.println("gifCount="+gifCount);
}
void drawProgressBar(Graphics g, int xpos, int ypos, int anchor) {
frame = gifd.getFrame(ind);
ind++;
if (ind >= gifCount) {
ind = 0;
}
g.drawImage(frame, xpos, ypos, anchor);//

 

循环绘图

}
////////////////////////////////////////////////////////////////////////////////// 

import java.util.Vector;
import java.io.InputStream;
import javax.microedition.lcdui.Image;
public class GIFDecode {
/**
* 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;
/**