AS3:复制 PNG 图像会导致透明度丢失
我使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
他的回答非常接近完整:
最后一个属性确保 Flash 在新图像中不包含背景。那应该可以解决你的问题。它必须恰好是“0”,而不是 0x000000。
His answer was very close to complete:
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.
创建
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 transparencyalso check the
transparent
property of the sourceBitmapData
正如错误所述,Bitmap 没有 copyChannel 方法:)
而不是这样:
您需要这样做:
Bitmap doesn't have a copyChannel method as the error says :)
Instead of this:
You need to do this: