PNG RGB transformation related to alpha in getImageData?

核能气质少年 提交于 2019-12-13 03:44:16

问题


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).

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

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).

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 ?


回答1:


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).

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.



来源:https://stackoverflow.com/questions/8388106/png-rgb-transformation-related-to-alpha-in-getimagedata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!