简体   繁体   English

为什么浏览器以不同的方式显示png中的颜色?

[英]Why are browsers displaying the colors in a png differently?

I have an app that generates a base64 png from drawings on an HTML canvas. 我有一个应用程序,从HTML画布上的图纸生成base64 png。

I found that when looking at the colors using an eye-dropper extension, I get different colors between Chrome and Firefox. 我发现当使用滴管扩展器查看颜色时,我会在Chrome和Firefox之间获得不同的颜色。 Neither of the browsers colors perfectly match the actual colors that I drew on the canvas (Chrome matched for 1 color). 两种浏览器颜色都不完全匹配我在画布上绘制的实际颜色(Chrome匹配1种颜色)。

First, I drew on the canvas in Firefox, and got the base64 png string. 首先,我在Firefox中绘制了画布,并获得了base64 png字符串。

I decoded that base64 here in both Chrome and Firefox: http://freeonlinetools24.com/base64-image 我在Chrome和Firefox中解码了base64: http//freeonlinetools24.com/base64-image

Note that I decoded the exact same base64 string (generated in FF), but got 2 different resulting images when decoding. 请注意,我解码了完全相同的base64字符串(在FF中生成),但在解码时得到了2个不同的结果图像。

You can use any color picker extension to see the difference in the colors hex codes or RGB values. 您可以使用任何颜色选择器扩展来查看颜色十六进制代码或RGB值的差异。

Here are all of the colors, including the hex code for what I actually drew on the canvas, and the observed hex code for both Chrome and Firefox. 以下是所有颜色,包括我在画布上实际绘制的十六进制代码,以及Chrome和Firefox的观察到的十六进制代码。 The background is transparent, so the grey/black are just a difference in how the browsers display the transparency. 背景是透明的,因此灰色/黑色只是浏览器显示透明度的一个区别。

Orange: 橙子:

  • Expected: #ff7f0e 预计:#ff7f0e
  • Chrome: #ff7f0c (close) Chrome:#ff7f0c(关闭)
  • Firefox: #f08327 Firefox:#f08327

Blue: 蓝色:

  • Expected: #1f77b4 预计:#1f77b4
  • Chrome: #1f77b4 (match) Chrome:#1f77b4(匹配)
  • Firefox: #3877b1 Firefox:#3877b1

Green: 绿色:

  • Expected: #2ca02c 预计:#2ca02c
  • Chrome: #2ca02b (close) Chrome:#2ca02b(关闭)
  • Firefox: #549d39 Firefox:#549d39

Red: 红色:

  • Expected: #d62728 预计:#d62728
  • Chrome: #d62627 (close) Chrome:#d62627(关闭)
  • Firefox: #c4352b Firefox:#c4352b

Firefox中png的屏幕截图 Chrome中png的屏幕截图 I don't understand why the base64 png wouldn't turn into the exact same RGB values across any browser. 我不明白为什么base64 png不会在任何浏览器中变成完全相同的RGB值。

Any ideas of what I can do to make the canvas.getDataURL() method return a base64 png that will have colors that match the colors that were drawn on it? 我可以做些什么来使canvas.getDataURL()方法返回一个base64 png,它的颜色与绘制的颜色相匹配?

I narrowed the problem down. 我把问题缩小了。 If I have a page with an img tag and set the src of the img tag to my image, the colors will render differently across different browsers. 如果我有一个带有img标签的页面并将img标签的src设置为我的图像,那么不同浏览器的颜色将呈现不同的颜色。

By and large canvas.getDataURL() returns a different image, which differs from the original image at least in quality and type. 总的来说, canvas.getDataURL()返回一个不同的图像,它与原始图像至少在质量和类型上不同。 To get original Base64 value use XMLHttpRequest + btoa or FileReader.readAsDataURL() . 要获得原始Base64值,请使用XMLHttpRequest + btoaFileReader.readAsDataURL()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM