Reputation: 5153
Using Flex 3, I would like to take an image snapshot such as this:
var logoSnapshot:ImageSnapshot = ImageSnapshot.captureImage(logoContainer);
and turn it into something that the Image class can use. I see that there is a property called "data", that holds a byteArray, so I guess my question is: How do I take an image that gets stored as a byteArray and convert it to something the Image class can use to display?
Upvotes: 3
Views: 4048
Reputation:
You can actually just set the ByteArray directly as the source property of the Image class in the current Flex SDK.
Upvotes: 0
Reputation: 17734
Simpler implementation that should work:
var bm : Bitmap = new Bitmap(ImageSnapshot.captureBitmapData(logoContainer));
Set "bm" as the source of your Image object.
Upvotes: 2
Reputation: 5242
It takes a few steps, but it isn't hard.
Draw your ByteArray to a BitmapData instance using setPixels()
.
Create a new BitmapAsset instance, and pass in your BitmapData.
Pass the BitmapAsset to your Image control's source
property.
This assumes that your ByteArray is compatible with setPixels()
. According to the docs, it needs to be a set of unsigned ints representing 32-bit ARGB values. If the ByteArray holds the image in another format, you'll have to find different way. If you're lucky, it'll be encoded as JPG, PNG, or GIF, and you'll be able to pass the ByteArray directly to source
on the Image, and Flash Player will already know how to interpret it.
Upvotes: 0
Reputation: 13974
The BitmapData class has:
public function setPixels(rect:Rectangle, inputByteArray:ByteArray):void
Set the rectangle to be the size of your image, and then send in the byteArray.
You should then be able to draw the BitmapData to your screen.
Upvotes: 0