10-23-2009 03:57 AM - edited 10-23-2009 03:58 AM
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.gi
f"); int len = input.available(); byte data = new byte[len]; input.read(data);
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(d
ata, 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 ?
Solved! Go to Solution.
10-23-2009 04:11 AM
"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."
10-23-2009 04:14 AM - edited 10-23-2009 04:15 AM
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.
10-23-2009 05:42 AM
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.
11-26-2009 04:20 PM
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.
11-26-2009 11:00 PM
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