我如何知道图像是否是“预乘 Alpha”?
我听说在进行图层混合等时只需要预乘 alpha。我如何知道我的原始图像是否是预乘 alpha?
I heard that only premultiplied alpha is needed when doing layer blending etc. How do I know if my original image is premultiplied alpha?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能。
您唯一可以检查的是它是否没有预乘。为此,请检查所有像素并查看是否存在比 alpha 允许的值更高的颜色值
if(max(col.r,col.g,col.b) > 255* alpha)//不是预乘
。任何其他情况都是不明确的,可以或不能预乘。您最好的猜测可能是假设它们并非如此,因为大多数 PNG 都是这种情况。编辑:实际上,即使我发布的代码也不起作用,因为有很多带有白色遮罩的 PNG,因此图像必须包含 alpha 为
0
的部分来确定首先是哑光色。You can't.
The only thing that you can check is if it's not premultiplied. To do it go over all the pixels and see if there is a color-value that has a higher value than the alpha would permit
if(max(col.r,col.g,col.b) > 255*alpha)//not premul
. Any other cases are ambiguous and could or could not be premultiplied. Your best guess is probably to assume that they aren't as that's the case for most PNGs.Edit: actually, not even the code that I posted would work as there are a lot of PNGs out there with white matte, so the image would have to include parts that have an alpha of
0
to determine the matte color first.Android
Bitmap
存储从带有预乘 Alpha 的 PNG 加载的图像。您无法以通常的方式从中获得非预乘的原始颜色。为了加载没有预乘 RGB 通道的图像,我必须使用此处的第 3 方
PNGDecoder
:http://twl.l33tlabs.org/#downloadsAndroid
Bitmap
stores images loaded from PNG with premultiplied alpha. You can't get non-premultiplied original colours from it in usual way.In order to load images without RGB channels being premultiplied I have to use 3rd party
PNGDecoder
from here: http://twl.l33tlabs.org/#downloads