主类是在外国网站上看的,忘了是哪个网站了。直接上主类的代码
package com.doll.decodegif;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.system.GIFEncodedImage;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;
//A field that displays an animated GIF.
public class AnimatedGIFField extends BitmapField
{
private GIFEncodedImage _image; //The image to draw.
private int _currentFrame; //The current frame in the animation sequence.
private int _width; //The width of the image (background frame).
private int _height; //The height of the image (background frame).
private AnimatorThread _animatorThread;
public AnimatedGIFField(GIFEncodedImage image)
{
this(image, 0);
}
public AnimatedGIFField(GIFEncodedImage image, long style)
{
//Call super to setup the field with the specified style.
//The image is passed in as well for the field to configure its required size.
super(image.getBitmap(), style);
//Store the image and it's dimensions.
_image = image;
_width = image.getWidth();
_height = image.getHeight();
//Start the animation thread.
_animatorThread = new AnimatorThread(this);
_animatorThread.start();
}
protected void paint(Graphics graphics)
{
//Call super.paint. This will draw the first background frame and handle any required focus drawing.
super.paint(graphics);
graphics.clear(this.getExtent());
//Don't redraw the background if this is the first frame.
if (true)
{
//Draw the animation frame.
graphics.drawImage(_image.getFrameLeft(_currentFrame), _image.getFrameTop(_currentFrame),
_image.getFrameWidth(_currentFrame), _image.getFrameHeight(_currentFrame), _image, _currentFrame, 0, 0);
}
}
//Stop the animation thread when the screen the field is on is
//popped off of the display stack.
protected void onUndisplay()
{
_animatorThread.stop();
super.onUndisplay();
}
//A thread to handle the animation.
private class AnimatorThread extends Thread
{
private AnimatedGIFField _theField;
private boolean _keepGoing = true;
private int _totalFrames; //The total number of frames in the image.
private int _loopCount; //The number of times the animation has looped (completed).
private int _totalLoops; //The number of times the animation should loop (set in the image).
public AnimatorThread(AnimatedGIFField theField)
{
_theField = theField;
_totalFrames = _image.getFrameCount();
_totalLoops = _image.getIterations();
}
public synchronized void stop()
{
_keepGoing = false;
}
public void run()
{
while(_keepGoing)
{
//Invalidate the field so that it is redrawn.
UiApplication.getUiApplication().invokeAndWait(new Runnable()
{
public void run()
{
//UiApplication.getUiApplication().getActiveScreen().invalidate();
_theField.invalidate();
}
});
try
{
//Sleep for the current frame delay before the next frame is drawn.
sleep(_image.getFrameDelay(_currentFrame) * 10);
}
catch (InterruptedException iex)
{} //Couldn't sleep.
//Increment the frame.
++_currentFrame;
if (_currentFrame == _totalFrames)
{
//Reset back to frame 0 if we have reached the end.
_currentFrame = 0;
++_loopCount;
//Check if the animation should continue.
if (_loopCount == _totalLoops)
{
_keepGoing = false;
}
}
}
}
}
}
附件里面是解析GIF图片的一个Demo工程 (这是在Eclipse上的 在BB自己的IDE里面我也测试过了)
分享到:
相关推荐
自己写的BlackBerry gif图片 显示包装类,包括BlackBerry线程应用知识
黑莓新浪微博 黑莓4.5新浪微博 黑莓8830新浪微博 显示黑莓客户端,本人亲测软件,非常不错,目前还在用,跟手机融为一体。 黑莓新浪微博 黑莓4.5新浪微博 黑莓8830新浪微博 显示黑莓客户端 黑莓新浪微博 黑莓4.5...
黑莓上的动态鱼缸主题,很少见啊,可用于83 87 88等机子,超漂亮。
包括BBIPCall黑莓来电显示主程序以及BBIPCall黑莓来电显示数据库生成程序
7290 bb blackberry黑莓7290 bb blackberry黑莓7290 bb blackberry黑莓7290 bb blackberry黑莓7290 bb blackberry黑莓7290 bb blackberry黑莓7290 bb blackberry黑莓7290 bb blackberry黑莓7290 bb blackberry黑莓...
Call Assistant 是Bbdev.org的招牌招聘,许久已经没有更新了, 目前作者在元旦期间将软件升级为了1.4.7版,我们来看看具体更新的内容: V1.4.7(2011.1.1) —————- 1.支持定义2个ip电话 2.可以从sd卡读取电话...
老黑莓OS经典软件合集大全,独家整理,适合黑莓blackberry 7XXX 8XXX 9XXX等黑莓老机型,格式为cod , alx,jad等格式;;怀旧经典,软件清单如下 Twitter70.zip WacaiBlackberry.zip [BerryCN.com_DZH_v5.18] XECurrency-...
黑莓blackberry阅读工具 支持格式txt
黑莓usb驱动是一款黑莓手机专用驱动,已经装了桌面管理器的电脑就不需要安装了。没有装桌面管理器,又想访问TF卡,装这个就可以了。驱动介绍相信大家在第一次使用黑莓手机连接电脑的时候都出现了没有反应的问题了,...
黑莓操作说明,BlackBerry Manual了解黑莓的第一步。
可以用黑莓来电归属地显示,黑莓 语电通 yuchcaller
国人翻译的黑莓UI指导, 可以让你开发出更符合黑莓使用习惯的界面
BlackBerry黑莓手机软件安装方法.pdf
此文档包括了黑莓所有的额快捷键,可以让大家进一步的去熟悉使用黑莓..blackberry
• 使用图像、图片甚至动态图片(GIF 格式)作为个人主页显示图片。 • 更新状态,让好友即时了解您的最新状况 BBM 2.6.0.30 更新内容 全新的强大 BBM 功能,让您全面掌控共享的消息和图片。 定时消息:设置聊天中...
在黑莓上使用的农历软件,适用所有型号。如:9000
黑莓说明书,中文输入法说明,很好的东东 支持黑莓,要的不是价格是性能!!
黑莓 blackberry8700g 游戏 软件 经典集合
• 使用图像、图片甚至动态图片(GIF 格式)作为个人主页显示图片。 • 更新状态,让好友即时了解您的最新状况 即刻免费下载 BBM! * 注意:这些功能暂不支持运行 2.3.x (Gingerbread) 的 Android 智能手机