Welcome!

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

Reply
Developer
Posts: 27
Registered: ‎06-08-2009
My Device: Not Specified
Accepted Solution

Loading a gif image using GIFEncodedImage

[ Edited ]

My requirement is to show an animated loading Gif in the UI.

 

Firstly, I added "loading.gif" to my project under images folder.

 

Used the following code to get the byte array:

 

InputStream input = getClass().getResourceAsStream("/images/loading.gif");

int len = input.available();
byte[] data = new byte[len];
input.read(data);

 Then, tried

 

EncodedImage gif = EncodedImage.createEncodedImage(data, 0, data.length);

The above returned a PNGEncodedImage. Why ? I was expecting a GIFEncodedImage.

I then tried

 

 

GIFEncodedImage gif = (GIFEncodedImage)EncodedImage.createEncodedImage(data, 0, data.length,"image/gif");

 

The above throws an IllegalArgumentException.

Once I get the GIFEncodedImage, I hope to use the following resource (LINK) to render the gif. Am I missing something ? What is the best way to load a gif image ?

 

 

 

Highlighted
Developer
Posts: 37
Registered: ‎09-15-2009
My Device: Not Specified

Re: Loading a gif image using GIFEncodedImage

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/...

 

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

Developer
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: Loading a gif image using GIFEncodedImage

[ Edited ]

Are you certain it's a GIF you're trying to load and not a PNG that has a GIF extension by mistake?

 

What magfed said.

Developer
Posts: 27
Registered: ‎06-08-2009
My Device: Not Specified

Re: Loading a gif image using GIFEncodedImage

Thanks. I somehow missed the bottom portion of the article. But the following work around mentioned in the article did not work for me on 4.2.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.

 

Even when I choose (check) that option and "OK" the settings, the IDE keeps loosing that setting (ie. the next I time I open the options window and look a the option, it remains unchecked). The Encoding format hasn't changed either.

 

Only the second solution (ie. rename file extention) worked.

New Developer
Posts: 6
Registered: ‎06-17-2009
My Device: Not Specified

Re: Loading a gif image using GIFEncodedImage

Hi,

 

I'm using the AnimatedGIFField class but I have a problem when I add this field and then a new thread start.
In that case, the GIF doesn't "play".

Why this happened?
Thanks in advance.

Developer
Posts: 27
Registered: ‎06-08-2009
My Device: Not Specified

Re: Loading a gif image using GIFEncodedImage

The frame delay in the gif could be different from the default  0.1 sec set in the animation thread. cross check the frame delay gif and tweek the delay in thread accordingly