1
votes

Is it possible to get the bitmap data from a component using ActionScript?

I dynamically load an image. onComplete I create a Flex Image component and add the loaded image to the source

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void 
{
     var image:Image = new Image();
     image.x = 0;
     image.y = 0;
     image.source = e.currentTarget.content;
     canvas.addChild(image); // canvas is already added as an MXML element.
 }

Later I want to create a new Image component and get the bitmapData from the first Image.

I have tried this

canvas.getChildAt(0)

Which seems to give me the Image, but I can not figure out how to get the bitmap data.

canvas.getChildAt(0).bitmapData; 

gives me a compile error "... undefined property"

Does anyone know how ot get the bitmap data so I can use it in my new Image component?

Thanks in advance,

Ran

3

3 Answers

2
votes

Cliff's answer will give you a screenshot of the Image; to get the underlying BitmapData for the image without doing a screenshot, you can try

 Bitmap(image.content).bitmapData

This should avoid any filters as well.

0
votes

This should do it.

var bd:BitmapData = new BitmapData(myComponent.width, myComponent.height, true, 0);
bd.draw(myComponent);