首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为BBM显示图片创建动画gif

为BBM显示图片创建动画gif
EN

Stack Overflow用户
提问于 2011-06-22 21:56:39
回答 4查看 68.6K关注 0票数 0

我想知道如何为Blackberry Messenger创建动画gif,我使用Total Video Converter将视频转换为动画gif,它在blackberry图片目录中正确显示为gif图像,但当用作blackberry messenger显示图片时,它不播放并显示未对齐,我已经看到几个blackberry messenger动画gif显示图片显示正确(即播放和正确对齐),是否有一种方法来创建动画gif从一个视频,将作为一个黑莓messenger显示图片播放

EN

回答 4

Stack Overflow用户

发布于 2011-07-09 19:57:33

BlackBerry smartphone应用程序编程接口集合中的BitmapField可用于显示图像;但是,它将仅显示动画GIF的第一帧。可以使用浏览器字段显示web内容中的动画GIF;但是,如果只需要显示动画图像,这可能会给应用程序带来不必要的开销。

下面的示例扩展BitmapField以创建一个名为AnimatedGIFField的新类。这个类可以被添加到屏幕上,并接受一个GIFEncodedImage,它将对其进行动画处理。

代码语言:javascript
运行
复制
/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);

    //Don't redraw the background if this is the first frame.
    if (_currentFrame != 0)
    {
        //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() 
                {
                    _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;
                }
            }
        }
    }
  }
}

注意:当应用程序被构建到.cod file中时,添加到项目中的图像将被automatically转换为Portable Network Graphics (PNG) format。这可能会在添加动画GIF时导致问题,因为此过程将剥离动画。有两种解决此问题的方法。

  1. 首先是在BlackBerry®Java®开发环境( png )中打开应用程序的项目属性,单击编译选项卡,然后选中不将图像文件转换为BlackBerry复选框。这将阻止转换应用程序中的所有图像,如果项目中的图像格式不是GIF和PNG,则转换效率会很低。
  2. 单个图像的解决方法是将.gif图像的扩展名更改为其他名称(如.bin)。这将阻止RIM应用程序编译器(RAPC)将图像转换为.png。

您也可以从here下载该文件作为.java文件

票数 1
EN

Stack Overflow用户

发布于 2012-02-13 23:46:08

你要做的就是..。

如果你还没有的话,在这里下载

  • http://www.photoscape.org/ps/main/download.php <<,这是safe..enter图像描述,
  • ,打开它,然后按一下make a gif,然后将图片拖到那里即可。
  • 一旦你拿到了你的照片。按下大小并选择"set canvas size“和”Set canvas size“

height on 150或更小,gif必须是正方形。然后你把它保存到你的黑莓,它应该工作

票数 1
EN

Stack Overflow用户

发布于 2011-07-09 14:00:06

GIF画布必须是方形的,并且其大小不得超过31Kb。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6441073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档