BitmapData 构造函数默认值似乎有冲突

发布于 2024-11-28 12:27:44 字数 1318 浏览 1 评论 0原文

根据我在这里给出的答案: AS 3 |克隆 Png 图像数据

我知道要获得透明的 BitmapData 对象,必须指定黑色背景颜色,但直到有人叫我这样做之前,我从来没有费心去检查原因。检查后,我想知道是否有一个原因我没有看到 BitmapData 构造函数的默认参数似乎有冲突?

首先,这是文档中定义的构造函数:

public function BitmapData(width:int, height:int, transparent:Boolean = true, fillColor:uint = 0xFFFFFFFF)

请注意,透明度的默认值为 true。现在考虑一下文档中关于透明参数的说法:

transparent:Boolean(默认值 = true)— 指定位图图像是否支持每像素透明度。默认值为 true(透明)。要创建完全透明的位图,请将透明参数的值设置为 true,并将 fillColor 参数的值设置为 0x00000000(或 0)。将透明属性设置为 false 可以稍微提高渲染性能。

好像说这个参数没有什么用,除非你把填充颜色设置为黑色。那么为什么默认的 fillColor 值是 0xFFFFFFFF 呢?

这对我来说似乎是错误的。如果开发人员想要获得无 Alpha 通道的性能增益,则必须显式指定:

var bmd:BitmapData = new BitmapData(width,height,false);

如果需要透明的 BitmapData,也必须显式指定:

var bmd:BitmapData = new BitmapData(width,height,true,0x000000);

因此,在不接受性能的情况下,我们决不能依赖最短的构造函数形式击中,我不明白为什么。当然,填充颜色应该默认为黑色:

var bmd:BitmapData = new BitmapData(width,height); // transparent BitmapData

或者透明度应该默认为假:

var bmd:BitmapData = new BitmapData(width,height); // faster, no-alpha BitmapData

任何人都可以向我解释当前构造函数的好处是什么?

Following on from an answer I gave here: AS 3 | Cloning Png image data

I knew that to get a transparent BitmapData Object it was necessary to specify a background color of black, but until I was called out on it I never bothered to check why. Having checked, I wonder if there is a reason I don't see for what seems like conflicting default arguments to the BitmapData constructor?

First, here is the constructor as defined in the documentation:

public function BitmapData(width:int, height:int, transparent:Boolean = true, fillColor:uint = 0xFFFFFFFF)

Please notice that the default value for transparency is true. Now consider what the docs say about the transparent parameter:

transparent:Boolean (default = true) — Specifies whether the bitmap image supports per-pixel transparency. The default value is true (transparent). To create a fully transparent bitmap, set the value of the transparent parameter to true and the value of the fillColor parameter to 0x00000000 (or to 0). Setting the transparent property to false can result in minor improvements in rendering performance.

It seems to say that this parameter is useless unless you set the fill color to black. So why then is the default fillColor value 0xFFFFFFFF?

This seems wrong to me. If a developer wants the performance gain of no alpha channel, it must be explicitly specified:

var bmd:BitmapData = new BitmapData(width,height,false);

And if a transparent BitmapData is required, that too must be explicitly specified:

var bmd:BitmapData = new BitmapData(width,height,true,0x000000);

So at no point can we rely on the shortest constructor form, without accepting a performance hit, and I can't understand why. Surely either the fillColor should default to black:

var bmd:BitmapData = new BitmapData(width,height); // transparent BitmapData

or transparency should default to false:

var bmd:BitmapData = new BitmapData(width,height); // faster, no-alpha BitmapData

Can anyone explain to me what the benefit of the current constructor is?

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

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

发布评论

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

评论(1

情话墙 2024-12-05 12:27:44

当前的构造函数没有任何好处——它只是默认的 Adob​​e 模式——我假设他们不希望人们抱怨在绘制显示对象、影片剪辑等时,位图包含背景。老实说,我认为不默认更有意义,但这正是他们选择的,我们必须遵守它。

如果您确实想要稍微提高速度并且不想指定该构造函数,请创建一个定义了该构造函数的最终子类:

public final class Surface extends BitmapData {
    public function Surface(width:int, height:int, fillColor:uint = 0x000000):void {
        super(width, height, false, fillColor);
    }    
}

There is no benefit of the current constructor -- it's just Adobe mode the default -- I'm assuming they didn't want people complaining that when drawing displayobjects, movieclips, etc, the bitmap contained a background. Honestly -- I think it would've made more sense to make no defaults, but that's just what they chose, and we have to abide by it.

If you really want a minor speed increase and don't want to specify that constructor, create a final subclass with that ctor defined:

public final class Surface extends BitmapData {
    public function Surface(width:int, height:int, fillColor:uint = 0x000000):void {
        super(width, height, false, fillColor);
    }    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文