在getImageData中与alpha相关的PNG RGB转换? [英] PNG RGB transformation related to alpha in getImageData?

查看:162
本文介绍了在getImageData中与alpha相关的PNG RGB转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PNG图像,其中一些像素的alpha为254.这些像素有这种颜色:
RGBA {183,221,129,254}(不是javascript表示法)。

I have a PNG image with some pixels having an alpha of 254. These pixels have this color : RGBA{183, 221, 129, 254} (not a javascript notation).

我可以在Gimp中查看R,G和B组件是183,221和129.

I can check in Gimp that the R, G and B components are 183, 221 and 129.

但当我读取像素时在Chrome中使用getImageData(在画布上),R,G和B值被修改为182,220和128(A正确地为254)。

But when I read my pixels in Chrome using getImageData (on a canvas) the R, G and B values are modified to 182, 220 and 128 (A being correctly 254).

这是标准化的转型还是虫子?如果这是正常的,我在哪里可以找到确切的公式来预测由PNG中的getImageData给出的RGB值?

Is that a standardized transformation or a bug ? If that's normal, where can I find the exact formula to predict RGB values given by getImageData from the ones in the PNG ?

推荐答案

这几乎肯定是由伽马校正引起的。简而言之,大多数Web浏览器会忽略图像中包含的颜色空间并使用默认颜色空间(因为不可能在没有大的性能损失的情况下使用颜色空间,尤其是插件,如Flash)。

It's almost certainly caused by gamma correction. In short, most web browsers ignore the colour-space included in the image and use the default one (as its impossible to get everything to use the colour space without a large performance penalty, especially plugins such as Flash).

如果您不关心真正的老浏览器(最值得注意的是Opera 6和Safari 1),您可以在没有任何伽玛信息的情况下保存图像。

Provided you don't care about really old browsers (Opera 6 and Safari 1 most notably), you can just save the image without any gamma information.

这篇关于在getImageData中与alpha相关的PNG RGB转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆