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
JamesColeman
Posts: 266
Registered: ‎04-24-2009
My Device: Not Specified
Accepted Solution

Get height and width of bitmap jpg or png file without loading file

Is there a way to get the hieght and width of an bitmap file, like jpg or png, without loading the entire image file first.

 

Thanks!

Please use plain text.
New Developer
neeraj
Posts: 20
Registered: ‎07-23-2008
My Device: Not Specified

Re: Get height and width of bitmap jpg or png file without loading file

no way you cant, but may i know why do u want these height and width before loading image.
Please use plain text.
Developer
Posts: 43
Registered: ‎09-28-2009
My Device: Not Specified

Re: Get height and width of bitmap jpg or png file without loading file

Hi JamesColeman,

 

While you can not access the width and height of the jpg or png without accessing the file, you can gain this information without accessing the whole file. A PNG for example (in raw hex) does indicate the width and height of the image it contains. The first 21 bytes contain the file specific information such as name, etc, however right after the IHDR header the first 4 bytes indicate Width and the next 4 bytes indicate Height. So this way you only need to read the first 29 bytes of the PNG to be able to get its dimensions, which while it still requires file access is considerably easier.

 

I have code available to read this information here and if you would like to know more about the specification you can find its information on this site.

 

Best Wishes

 

Andre

Please use plain text.
Developer
JamesColeman
Posts: 266
Registered: ‎04-24-2009
My Device: Not Specified

Re: Get height and width of bitmap jpg or png file without loading file

Excellent.  Very specific information. Thanks for your assistance!

 

neeraj asked why I was concerned.  I find that I REALLY have to pay attention to resources such as memory use, I/O use, and CPU use, or I can slow down the Blackberry to a crawl making it useless to the end user.  The little things may not seem like much by themselves, but they can really add up.  The way I originally coded my program, it took over a minute to load.  So I must consider the time it would take to open several large bitmap files in a row, when all I need to know is there size. 

Please use plain text.