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

Adobe AIR Development

Reply
Developer
Posts: 88
Registered: ‎05-24-2009
My Device: Not Specified
Accepted Solution

Load Image and get BitmapData from it

Hello.

 

I use the qnx.ui.display.image class to load an image that is in the package with teh application, and this works fine. However i am looking at a bunch of functions that take BitmapData format of an Image, and i am wondering how to load an image in a BitmapData format, or how to convert the qnx.ui.display.image class to give me the BitmapData form it.

 

Thanks in Advance.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Load Image and get BitmapData from it

Note that Image can take a URL, Bitmap, or BitmapImage in setImage().  And it has a cache property which is a qnx.utils.ImageCache.

 

qnx.utils.ImageCache.getImage() apparently returns a BitmapData.  It looks like you'd need to know what URL the cache stores it under.  Not sure how you'd discover that unless the image had been loaded from a URL in the first place.

 

The docs for BitmapData say that you can load one using flash.display.Loader, so presumably if you were loading it from a URL that would let you get it directly, bypassing the ImageCache stuff.

 

(I don't have a direct answer, sorry.)


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 88
Registered: ‎05-24-2009
My Device: Not Specified

Re: Load Image and get BitmapData from it

Thanks.

Highlighted
Developer
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS

Re: Load Image and get BitmapData from it

ImageCache won't always return the image and it also requires prior knowledge of the image's url. To retrieve the actual Bitmap from an Image object use the following:

 

 

(img.getChildAt(0) as Bitmap).bitmapData

 

 

img being your Image object.

 

Ends up the Bitmap is actually a child of the image object.

From,
Noah NU
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Load Image and get BitmapData from it

@rever, sounds like Noah found the real solution here.  You could use the Options menu next to my earlier answer to mark it as not being the solution, then go back and "Accept" Noah's new answer.

 

Also, I believe "Bitmap(img.getChildAt(0)).bitmapData" would be the preferred approach, though I believe the two do roughly the same thing in this case.

 

(They would differ at least in the exception raised if the 1st child turned out not to be a Bitmap object.)


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 382
Registered: ‎05-19-2008
My Device: BlackBerry Torch
My Carrier: AT&T

Re: Load Image and get BitmapData from it

You might also look at my post as well where I tackled similar issues.

 

In short, if you use the QNX Image object, you can load image files directly and don't need to use bitmapData class at all. 

Bill
-------------------------------------------
Check out my book on BlackBerry Development for Java.
And my other really really old book
My Apps: FlashKids