简体   繁体   中英

Flex: Copying bitmapData of a loaded image into another SWFLoader

I have 2 SWFLoaders like so:

<mx:SWFLoader width="10" height="10" complete="imageLoaded()" id="ldr_src" source="img.jpg" scaleContent="true"/>
<mx:SWFLoader id="ldr_target" scaleContent="true"/>

private function imageLoaded():void{
     var bm:Bitmap = new Bitmap(ImageSnapshot.captureBitmapData(ldr_src);
     ldr_target.source = bm;
}

Everything here works as expected, except one little small thing:

I load an image of size 100x100 in ldr_src(which is 10x10). The bitmap is copied in ldr_target, but with unexpected results. I would've thought a 10x10 size of the loaded image would be copied. Instead the bitmap from (0,0) to (10,10) of the loaded image is copied to the target.

No matter what the actual size of the image, how do I copy the bitmapData of the size which is scaled down by the swfLoader?

Pass the image.content into ImageSnapshot.captureBitmapData , then make sure the width/height of the ldr_target is set equal to the src:

<mx:SWFLoader width="10" height="10" complete="imageLoaded()" id="ldr_src" source="img.jpg" scaleContent="true"/>
<mx:SWFLoader width="10" height="10" id="ldr_target" scaleContent="true"/>

private function imageLoaded():void
{
    var bm:Bitmap = new Bitmap(ImageSnapshot.captureBitmapData(ldr_src.content));
    ldr_target.source = bm;
}         

Lance

I was trying to do something similar but with a Video source rather than an Image. Worked like a charm, thanks. (For some reason the "ImageSnapshot" class is a really well-kept secret at Adobe.)

您还可以使用BitmapData.draw方法获取实现IBitmapDrawable的DisplayObject的快照。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM