01-19-2011 03:20 PM
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.
Solved! Go to Solution.
01-19-2011 04:11 PM
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.)
01-19-2011 04:31 PM
Thanks.
02-21-2011 01:19 PM
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.
02-21-2011 01:30 PM
@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.)
02-21-2011 02:37 PM
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.