`
doll
  • 浏览: 82869 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Blackberry 上显示动态 GIF 图片

阅读更多
主类是在外国网站上看的,忘了是哪个网站了。直接上主类的代码
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平台上创建一个GIF图片显示包装类,并结合BlackBerry线程应用知识,确保程序的性能和流畅性。 首先,理解GIF图片格式是至关重要的。GIF是一种支持动画的位图格式,它通过在一个...

    黑莓上的动态鱼缸主题,很少见啊

    "动态鱼缸主题"是指这种主题包含有动态元素,也就是说,不仅背景是静态的图片,而是有着动态的画面,如鱼儿在屏幕上游动,可能会有气泡上升、水草摇曳等效果,这些元素给用户带来更真实的视觉享受。这样的主题通常...

    黑莓4.5 8830新浪微博 发微博显示黑莓客户端

    黑莓新浪微博 黑莓4.5新浪微博 黑莓8830新浪微博 显示黑莓客户端,本人亲测软件,非常不错,目前还在用,跟手机融为一体。 黑莓新浪微博 黑莓4.5新浪微博 黑莓8830新浪微博 显示黑莓客户端 黑莓新浪微博 黑莓4.5...

    BBIPCall黑莓来电显示

    BBIPCall是一款专门为黑莓(BlackBerry)手机设计的来电显示增强应用,旨在提升用户的通话体验。这款软件不仅提供基本的来电显示功能,还能通过数据库生成程序为用户提供更丰富的信息,比如联系人的详细资料、通话...

    黑莓8700 充电状态显示

    在黑莓8700上,充电状态通常会通过一个小电池图标和百分比显示来告知用户当前的电量,同时也会有相应的提示信息表明设备正在充电。 其次,描述中提到“4.2和4.5都能”,这可能指的是黑莓8700的操作系统版本。...

    黑莓blackberry Anyview

    黑莓blackberry阅读工具 支持格式txt

    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黑莓7290 bb blackberry黑莓...

    blackberry chinese黑莓 中文

    本文将详细讲解如何在黑莓设备上设置和使用中文输入法。 1. **输入区域设置(Input Locale)** 黑莓手机支持多语言输入,包括中文。在设置中找到“Options”(选项),然后进入“Localization”(本地化),在此处...

    黑莓桌面管理器 BlackBerry Desktop Manager 5.0.1 B73多国语言版

    黑莓桌面管理器(BlackBerry Desktop Manager)是为黑莓设备设计的一款桌面软件,旨在帮助用户更高效地管理其黑莓手机上的数据与应用程序。通过该软件,用户能够轻松实现数据同步、备份以及恢复等功能。本篇文章将...

    老黑莓OS经典软件合集大全,独家整理,适合黑莓blackberry 7XXX 8XXX 9XXX等黑莓老机型.zip

    老黑莓OS经典软件合集大全,独家整理,适合黑莓blackberry 7XXX 8XXX 9XXX等黑莓老机型,格式为cod , alx,jad等格式;;怀旧经典,软件清单如下 Twitter70.zip WacaiBlackberry.zip [BerryCN.com_DZH_v5.18] XECurrency-...

    黑莓9900来电归属地显示软件语电通

    然而,尽管黑莓9900在很多功能上表现出色,但在来电归属地显示方面却存在一定的局限性。本文将深入探讨这一问题,并介绍一款名为“语电通”的软件,帮助用户改善来电归属地的显示效果。 语电通是一款专为黑莓手机...

    黑莓上的来电显示软件CallAssistant_V1_4_7

    Call Assistant 是Bbdev.org的招牌招聘,许久已经没有更新了, 目前作者在元旦期间将软件升级为了1.4.7版,我们来看看具体更新的内容: V1.4.7(2011.1.1) —————- 1.支持定义2个ip电话 2.可以从sd卡读取电话...

    黑莓blackberry8700g游戏软件经典集合

    黑莓Blackberry 8700g是一款经典的智能手机,它在2006年推出,以其独特的全键盘和优秀的电子邮件功能赢得了商务人士的青睐。这款手机不仅在通信和办公方面表现出色,还拥有一定的娱乐功能,包括游戏和各种实用软件。...

    黑莓桌面管理器4.2

    用户可以方便地在电脑和黑莓手机之间传输文件,如音乐、图片、视频等,满足多媒体娱乐需求。 8. **多语言支持** 作为"Blackberry_Desktop_Manager_420_b018_multilanguage"的命名,表明该版本支持多种语言,使得...

    在黑莓上使用的农历软件

    在黑莓手机上使用的农历软件是专门为这款经典智能手机平台设计的应用程序,旨在帮助用户查看和管理农历日期。黑莓手机以其高效的工作效率和强大的商务功能而闻名,而农历软件的加入,使得它更加贴近中国用户的日常...

    黑莓上的MSN客户端

    在黑莓设备上安装MSN客户端,可以方便地在手机上与朋友、家人和同事保持联系。 **1. 黑莓与MSN的结合** 黑莓MSN客户端允许用户在黑莓手机上无缝接入MSN网络。通过这个客户端,你可以享受到与桌面版MSN Messenger...

    黑莓手机usb驱动(BlackBerry USB Driver)

    黑莓usb驱动是一款黑莓手机专用驱动,已经装了桌面管理器的电脑就不需要安装了。没有装桌面管理器,又想访问TF卡,装这个就可以了。驱动介绍相信大家在第一次使用黑莓手机连接电脑的时候都出现了没有反应的问题了,...

    黑莓BlackBerry手机主题制作使用教程

    【黑莓BlackBerry手机主题制作使用教程】 在本文中,我们将深入探讨如何制作适用于BlackBerry设备的主题。首先,我们需要了解制作BlackBerry主题所需的基本软件工具,包括Java Development Environment (JDE)、...

Global site tag (gtag.js) - Google Analytics