Flex:将加载图像的位图数据复制到另一个 SWFLoader 中

发布于 2024-08-21 05:25:29 字数 593 浏览 2 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

琉璃梦幻 2024-08-28 05:25:29

image.content 传递到 ImageSnapshot.captureBitmapData,然后确保 ldr_target 的宽度/高度设置为等于 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

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

挽手叙旧 2024-08-28 05:25:29

我试图做类似的事情,但使用视频源而不是图像。非常有效,谢谢。 (出于某种原因,“ImageSnapshot”类在 Adob​​e 中确实是一个保守的秘密。)

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.)

朮生 2024-08-28 05:25:29

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

You can also use the BitmapData.draw method to get a snapshot of a DisplayObject that implements IBitmapDrawable

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文