Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 326
Registered: ‎02-02-2009
My Device: Not Specified

How to add gif images

net.rim.device.api.system.EncodedImage bg1px1 =net.rim.device.api.system.EncodedImage.getEncodedImageResource("loading.gif");



i tried to print gif image with above code, but it is not printing images, frnds help me to solve  this problem , post sample code....................

with regards Mohammed Basheer, cochin, kerala, India

Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to add gif images

BB does not support animated gifs, i guess you try to use one of these.
if you want to create an animation you have to store the pictures frame by frame.
I would suggest to use png as the BB handles all pictures as png internally.
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
BlackBerry Development Advisor
Posts: 15,882
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: How to add gif images

The BlackBerry API set does not have built in support for animated GIFs, but we do have a sample that shows how to display them.


How To - Display an animated GIF
Article Number: DB-00652


Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Posts: 18
Registered: ‎10-23-2012
My Device: 9500
My Carrier: Airtel

Re: How to add gif images

package com.jumper.utility;

import net.rim.device.api.ui.UiApplication;
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);

protected void paint(Graphics graphics)
//Call super.paint. This will draw the first background frame and handle any required focus drawing.

//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()

//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()
//Invalidate the field so that it is redrawn.
UiApplication.getUiApplication().invokeAndWait(new Runnable()
public void run()

//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.

if (_currentFrame == _totalFrames)
//Reset back to frame 0 if we have reached the end.
_currentFrame = 0;


//Check if the animation should continue.
if (_loopCount == _totalLoops)
_keepGoing = false;

then use this..


GIFEncodedImage bitmapImage=(GIFEncodedImage)GIFEncodedImage.getEncodedImageResource("img/loader.gif");
AnimatedGIFField image_field=new AnimatedGIFField(bitmapImage);