views:

402

answers:

3

Hi

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

+2  A: 

Check out ImageSnapshot.captureBitmapData()

http://livedocs.adobe.com/flex/3/langref/mx/graphics/ImageSnapshot.html

cliff.meyers
Thanks, the captureBitmapData did it!Do you know if it is possible to capture the bitmap without any applied filters?
Ran
+1  A: 

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.

Michael Brewer-Davis
A: 

This should do it.

var bd:BitmapData = new BitmapData(mymyComponent.width, myComponent.height, true, 0);
bd.draw(myComponent);
Sophistifunk
Gah, I misread the question as well. Michael is right, my code is for taking screenshots of any old component.
Sophistifunk