AS3:复制 PNG 图像会导致透明度丢失

发布于 2024-12-14 13:18:18 字数 829 浏览 7 评论 0原文

我使用 LoaderMax 加载外部 PNG 并在许多地方显示它,因此我使用以下代码来复制图像:

var cd:ContentDisplay = ContentDisplay(loader.getContent("name"));
var b1 = Bitmap(cd.rawContent);
var old = b1.bitmapData;
var bmp = new Bitmap(b1);

container.addChild(bmp);

原始图像在 Alpha 通道上有 50%,但是当我从相同的位图数据创建新位图时对象,它不保留 Alpha 通道。

如果我尝试复制 Alpha 通道(请参阅下面的代码;如果我理解正确的话,Alpha 通道会从自身复制到自身)- 透明度位于新图像上,但代码会引发错误...

bmp.copyChannel(old, new Rectangle(0, 0, old.width, old.height), new Point(), BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA);

错误:

ReferenceError: Error #1069: Property copyChannel not found on flash.display.Bitmap and there is no default value.
    at barmask/frame1()

如何复制 PNG 并保持 alpha 透明度...最好没有错误?

Ps 请原谅任何明显的错误,我是 ActionScript 新手......

I am using LoaderMax to load an external PNG and display it in many places so I use the following code to duplicate the image:

var cd:ContentDisplay = ContentDisplay(loader.getContent("name"));
var b1 = Bitmap(cd.rawContent);
var old = b1.bitmapData;
var bmp = new Bitmap(b1);

container.addChild(bmp);

The original image has a 50% on the alpha channel, but when I create the new bitmap from from the same bitmapData object, it does not preserve the alpha channel.

If I try to copy the alpha channel (see the code below; if I understand correctly, the alpha channel is copied from itself, to itself)- the transparency is on the new image , but the code throws an error...

bmp.copyChannel(old, new Rectangle(0, 0, old.width, old.height), new Point(), BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA);

Error:

ReferenceError: Error #1069: Property copyChannel not found on flash.display.Bitmap and there is no default value.
    at barmask/frame1()

How can I duplicate a PNG and maintain the alpha transparency... preferably without the error?

P.s. Please forgive any obvious mistakes, I am a ActionScript Newb...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

夏夜暖风 2024-12-21 13:18:18

他的回答非常接近完整:

new BitmapData(w, h, true, 0); 

最后一个属性确保 Flash 在新图像中不包含背景。那应该可以解决你的问题。它必须恰好是“0”,而不是 0x000000。

His answer was very close to complete:

new BitmapData(w, h, true, 0); 

The last property ensuring that flash doesn't include a background in the new image. That should solve your issue. It has to be exactly "0", not 0x000000, either.

落花随流水 2024-12-21 13:18:18

创建 BitmapData 实例,将 3 个参数传递给构造函数:new BitmapData(w, h, true)Boolean值为透明度
另请检查透明BitmapData 的 code> 属性

create your BitmapData instance, passing 3 parameters to the constructor: new BitmapData(w, h, true), Boolean value is transparency
also check the transparent property of the source BitmapData

作妖 2024-12-21 13:18:18

正如错误所述,Bitmap 没有 copyChannel 方法:)

而不是这样:

bmp.copyChannel(...

您需要这样做:

bmp.bitmapData.copyChannel(...

Bitmap doesn't have a copyChannel method as the error says :)

Instead of this:

bmp.copyChannel(...

You need to do this:

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