为什么浏览器在OSX上呈现rgba的方式不同? [英] Why do browsers render rgba differently on OSX?

查看:124
本文介绍了为什么浏览器在OSX上呈现rgba的方式不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编写一些颜色处理代码,并在alpha上停留了很长时间,然后(两个小时后)我意识到浏览器呈现rgba的方式有所不同。

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.

我创建了此测试: http://jsbin.com/adekez/2/
添加/ edit来查看代码

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

以下是OSX Lion中4种浏览器的结果: http://imgur.com/g2iqu

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

该元素的背景为rgba(0,0,0,0.5

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

我的十六进制计算器说:FF÷2 = 7F.8这意味着

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

#808080上的Safari是正确的
#7F7F7F上的Firefox关闭了1
#7E7E7E上的Opera关闭了2
Chrome在#929292上的Chrome浏览器已关闭

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

这是怎么回事,这是Chrome中的bug还是我只是不了解颜色(true)?

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

推荐答案

先行



嗯,实际上是Safari Firefox a都正确:
0xFF = 255 255/2 = 127.5 。因此 128 可能是正确的( 0x80 ),但 127 ( 0x7F )-取决于浏览器的四舍五入约定。

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.

这些都是四舍五入的问题。我不太明白为什么会有舍入问题,因为0.5可以用二进制数表示而没有精度损失,但是实际上存在舍入问题:

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:

Opera:

Chrome浏览器:

Chrome:

这篇关于为什么浏览器在OSX上呈现rgba的方式不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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