AS3 加载器忽略 .png 透明度
在 Flash CS4 中,打开一个新文档,将背景颜色更改为可识别的颜色(例如洋红色)并添加以下代码:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event){addChild(e.target.content);});
loader.load(new URLRequest('newsnakelub8.png'));
...将 .png 文件名替换为您手边的任何文件名,我抓住了 这个。 编译 .swf,和我一起叹息一声——通常透明的 .png 现在有白色背景,不允许 Flash 背景颜色显示出来。
我是否在某个地方缺少了一个神奇的“treatAsPNG24”属性?
In Flash CS4, open a new document, change the background colour to something recognizeable (like magenta) and add the following code:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event){addChild(e.target.content);});
loader.load(new URLRequest('newsnakelub8.png'));
... replacing the .png filename with any you happen to have handy, I grabbed this one. Compile the .swf, and join me in a sigh of disapointment - the normally transparent .png now has a white background, not allowing the flash background colour to show through.
Is there a magical 'treatAsPNG24' property that I'm missing somewhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
该图像实际上没有透明背景...
(来源:liranuna.com)
为了您的高兴,固定图像:
The image doesn't actually have a transparent background...
(source: liranuna.com)
For your pleasure, fixed image:
问题是你的png。 尝试在 Photoshop 中打开它,它也不会是透明的。 尝试一种不同的 - 谷歌搜索,或者从 Flash 或 PS 发布一个 - 它会工作得很好。 (也就是说,没有要调用的设置,您只需要一个正确的图像。)
The problem is your png. Try opening it in Photoshop and it won't be transparent there either. Try a different one - google it, or publish one from Flash or PS - and it will work fine. (That is, there's no setting to invoke, you just need a proper image.)
这样做会加载白色背景的图像。 参数 ,
true,0x00ffffff 需要添加到 BitmapData 构造函数中。 我发现这个线程是因为我的 PNG 加载了白色背景,而且我知道它们有透明背景。 所以,希望这能帮助那些和我有同样问题的人。
Doing something like this will load Images with white backgrounds. The parameters ,
true, 0x00ffffff needs to be added to the BitmapData constructor. I found this thread because I was having white backgrounds loaded with my PNGs, and I knew they had transparent backgrounds. So, hopefully this will help anyone that had the same issue I did.
因为最好教你如何钓鱼...
如果你使用GIMP 2(像啤酒一样免费),只需打开图像,选择图层| 透明度... | Color to Alpha并选择您想要转换为透明背景的颜色。
Since it's better to teach you how to fish...
If you're using GIMP 2 (free as in beer), just open the image, select Layer | Transparency... | Color to Alpha and pick the color you want to be converted to the transparent background.