AS3 加载器忽略 .png 透明度

发布于 2024-07-27 14:50:15 字数 519 浏览 5 评论 0原文

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

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

发布评论

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

评论(4

゛时过境迁 2024-08-03 14:50:15

该图像实际上没有透明背景...

替代文字
(来源:liranuna.com

为了您的高兴,固定图像:

“替代文本”

The image doesn't actually have a transparent background...

alt text
(source: liranuna.com)

For your pleasure, fixed image:

alt text

茶花眉 2024-08-03 14:50:15

问题是你的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.)

念﹏祤嫣 2024-08-03 14:50:15
    public static function getSource(stringURL:String):void {
        currentProcessedURL = stringURL;
        var loader:Loader = new Loader();
        var request:URLRequest = new URLRequest(stringURL);
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
        loader.load(request);               
    }

    private static function onComplete(e:Event):void {
        try{
            var bitMap:BitmapData = new BitmapData(
                (e.currentTarget as LoaderInfo).loader.width,
                (e.currentTarget as LoaderInfo).loader.height);
            bitMap.draw((e.currentTarget as LoaderInfo).loader);
            var icon:BitmapSymbol = new BitmapSymbol();
            icon.source = bitMap;
            standardStringToImage[currentProcessedURL] = icon;      
            getSource(ALL_ARRAY.pop());
        } catch(e:Error) {
            trace(e);
        }           
    }

这样做会加载白色背景的图像。 参数 ,
true,0x00ffffff 需要添加到 BitmapData 构造函数中。 我发现这个线程是因为我的 PNG 加载了白色背景,而且我知道它们有透明背景。 所以,希望这能帮助那些和我有同样问题的人。

    public static function getSource(stringURL:String):void {
        currentProcessedURL = stringURL;
        var loader:Loader = new Loader();
        var request:URLRequest = new URLRequest(stringURL);
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
        loader.load(request);               
    }

    private static function onComplete(e:Event):void {
        try{
            var bitMap:BitmapData = new BitmapData(
                (e.currentTarget as LoaderInfo).loader.width,
                (e.currentTarget as LoaderInfo).loader.height);
            bitMap.draw((e.currentTarget as LoaderInfo).loader);
            var icon:BitmapSymbol = new BitmapSymbol();
            icon.source = bitMap;
            standardStringToImage[currentProcessedURL] = icon;      
            getSource(ALL_ARRAY.pop());
        } catch(e:Error) {
            trace(e);
        }           
    }

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.

恋竹姑娘 2024-08-03 14:50:15

因为最好教你如何钓鱼...

如果你使用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.

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