Why do browsers render rgba differently on OSX?

走远了吗. 提交于 2019-12-04 13:37:05

问题


I was trying to code up some color manipulation code and was stuck for a long time with alpha, then I (2 hours later) realized browsers render rgba differently.

I created this test: http://jsbin.com/adekez/2/ add /edit to look at the code

Here are the results in 4 browsers in OSX Lion: http://imgur.com/g2iqu

That is an element with a background of rgba(0,0,0,0.5) on top of white.

My hex calculator says: FF÷2 = 7F.8 which means

Safari at #808080 is correct Firefox at #7F7F7F is off by 1 Opera at #7E7E7E is off by 2 Chrome at #929292 is way off

What's going here, is this a bug in Chrome or do I just not know about colors (true)?


回答1:


First off

Well, actually Safari and Firefox are both correct: 0xFF = 255, 255 / 2 = 127.5. So 128 may be correct (0x80), but also 127 (0x7F) - depending on the rounding convention of the browser.

Explantion of the issue

These are rounding issues. I don't quite get why there are rounding issues, since 0.5 is representable in binary numbers without precision loss, but there are, in fact rounding issues:

Opera:

Chrome:




回答2:


When I checked in chrome & safari, But I got exact same rgba color #808080 in both. Let us know which browser version you are using.



来源:https://stackoverflow.com/questions/9338827/why-do-browsers-render-rgba-differently-on-osx

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