I have 2 SWFLoaders lik开发者_运维百科e 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.)
You can also use the BitmapData.draw method to get a snapshot of a DisplayObject that implements IBitmapDrawable
精彩评论