开发者

create animated gif for BBM display picture

Would want to know how to create an a开发者_如何学Gonimated gif for Blackberry Messenger, i converted a video to an animated gif using Total Video Converter, it shows properly as a gif image on blackberry picture directory but when used as a blackberry messenger display pic, it does not play and appears misaligned, I have seen several blackberry messenger animated gif display pictures that show properly(i.e play and are properly aligned), is there a way to create animated gif from a video that would play as a blackberry messenger display picture


The BitmapField within the BlackBerry smartphone application programming interface (API) set can be used to display images; however, it will only show the first frame of an animated GIF. Animated GIFs within web content can be displayed using a browser field; however, this can introduce unnecessary overhead into your application if you only need to display an animated image.

The following sample extends BitmapField to create a new class called AnimatedGIFField. This class can be added to a Screen and accepts a GIFEncodedImage, which it will animate.

/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;
                }
            }
        }
    }
  }
}

NOTE: Images added to a project are automatically converted into the Portable Network Graphics (PNG) format when the application is built into a .cod file. This can cause an issue when adding an animated GIF because this process will strip out the animation. There are two workaround options for this issue.

  1. The first is to open the Project Properties for your application in the BlackBerry® Java® Developement Environment (BlackBerry JDE), click on the compile tab and check the Don’t convert image files to png checkbox. This will prevent all images in the application from being converted, which can be inefficient if you have images in formats other than GIF and PNG in your project.

  2. The workaround for an individual image is to change the extension of your GIF image from .gif to something else (such as .bin). This will prevent the RIM Application Program Compiler (RAPC) from converting the image into a .png.

You can also download this as a .java file from here


All you have to do is..

  • if you don't already have it download photoscape http://www.photoscape.org/ps/main/download.php << this one is safe..enter image description here

  • Open it and then press on make a gif and then just drag pictures there.

  • once you got your pictures. Press on the size and select "set canvas size"

  • Set both with and height on 150 or smaller and the gif MUST be a square. Then you save it to your blackberry and it should work


A GIF canvas must be square and it's size must not exceed than 31Kb.


Old but just for the record, you can create animated bbm display pictures online for free at http://www.flashdp.net

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜