Flex:将加载图像的位图数据复制到另一个 SWFLoader 中
我有 2 个 SWFLoader,如下所示:
<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;
}
这里的所有内容都按预期工作,除了一件小事:
我在 ldr_src 中加载尺寸为 100x100 的图像(即 10x10)。位图被复制到 ldr_target 中,但出现意外结果。我本以为会复制 10x10 大小的加载图像。相反,加载图像的 (0,0) 到 (10,10) 的位图将复制到目标。
无论图像的实际大小是多少,如何复制被swfLoader缩小后的大小的bitmapData?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
image.content
传递到ImageSnapshot.captureBitmapData
,然后确保 ldr_target 的宽度/高度设置为等于 src:Lance
Pass the
image.content
intoImageSnapshot.captureBitmapData
, then make sure the width/height of the ldr_target is set equal to the src:Lance
我试图做类似的事情,但使用视频源而不是图像。非常有效,谢谢。 (出于某种原因,“ImageSnapshot”类在 Adobe 中确实是一个保守的秘密。)
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 的快照
You can also use the BitmapData.draw method to get a snapshot of a DisplayObject that implements IBitmapDrawable