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
Regular Contributor
Posts: 80
Registered: ‎10-20-2010
My Device: 8707
Accepted Solution

png to bitmap error

I am trying to convert a png file to a bitmap and log the errors. However, when i get to this part bitmap = image.getBitmap();     it will throw me a Uncaught: IllegalArgumentException.Am I doing something wrong? Why can't I use the getBitmap()? Thanks!

 

 

byte[] data = new byte[(int) file.fileSize()];
                        input.read(data);
                        image = EncodedImage.createEncodedImage(data, 0, data.length) ;
                        bitmap = image.getBitmap();   

Regular Contributor
Posts: 80
Registered: ‎10-20-2010
My Device: 8707

Re: png to bitmap error

I have removed bitmap = image.getBitmap();   and using only   image = EncodedImage.createEncodedImage(data, 0, data.length) ; And when it is display on screen , it shows PNGEncodedImage@10d801c.

 

How do I decode this image with getting an exception?

Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: png to bitmap error

How big is the PNG? As in width by height?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Regular Contributor
Posts: 80
Registered: ‎10-20-2010
My Device: 8707

Re: png to bitmap error

It is a very small image, about 63.6 KB.

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: png to bitmap error

What about width and height? A PNG can compress an image a great deal if a pattern in the colors exist, but it the image is too large then BlackBerry will complain and won't give you a Bitmap.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Regular Contributor
Posts: 80
Registered: ‎10-20-2010
My Device: 8707

Re: png to bitmap error

[ Edited ]

It is 225 x 225. Is it too large?

 

I am not sure why some of my images are not giving me bitmap as some images I can get the bitmap. Why is this so? Anyone has any ideas?

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: png to bitmap error

In that case it is odd. Does the exception give any details or is "message" null?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Regular Contributor
Posts: 80
Registered: ‎10-20-2010
My Device: 8707

Re: png to bitmap error

It states that Uncaught: IllegalArgumentException. When I open the image from sd card, I notice that the code is somewhat distorted. Will this be the reason it is not being converted to bitmap?

 

I have a program which manage to decode it to bitmap in android. But I can't seem to be able to do so in blackberry.

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: png to bitmap error

I'm not getting what you mean by "code is somewhat distorted." The image comes out distorted or something else?

 

Can you draw the EncodedImage?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 329
Registered: ‎12-17-2010
My Device: Not Specified
My Carrier: developer

Re: png to bitmap error

i prefer you use png optimizer then it will decrease the file size..........