Javascript:检测单色显示 [英] Javascript: detect monochrome display

查看:160
本文介绍了Javascript:检测单色显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在电子书阅读器上测试一个HTML5网络应用程序,我得到它主要工作,但颜色都搞砸了(它是单色的)。我的应用程序使用大量颜色,每秒更新一次。我需要这个也可以在彩色显示器上运行,所以我需要检测它是否是单色的。

I've been testing an HTML5 webapp on eReaders, and I got it mostly working, but the colors are all messed up (it's monochrome). My app uses lots of colors with an update every second. I need this to run on colored displays as well, so I need to detect if it's monochrome.

我正在使用的电子阅读器由索尼制造,它报告 screen.pixelDepth screen.colorDepth 同为16,这与我支持的大多数其他设备不同(24和32)很常见)。

The eReader that I'm using is made by Sony, and it reports screen.pixelDepth and screen.colorDepth as both 16, which IS different than most other devices I support (24 and 32 are common).

到目前为止,我的想法是:

My ideas so far are:


  • 始终显示单色报告16位颜色的设备

  • 从User-Agent / navigator.appVersion

  • 来自画布的样本位(虽然我认为也可能是谎言)

假设16位颜色=是否安全单色?还是有另外一个我可以忽略的技巧会更可靠吗?

Is it safe to assume that 16-bit color = monochrome? Or is there another trick that I could be overlooking that would be more reliable?

推荐答案

在计算中,单色通常是2比特,16位显示通常称为灰度(尽管它可能是其他颜色的阴影)。

In computing, "monochrome" is usually 2 bit, a 16 bit display is usually called greyscale (though it might be in shades of some other colour).

考虑使用调色板,颜色转换为适当的16位值而不是设备嗅探。您可以从网页安全调色板开始。

Consider using a palette where the colours convert to appropriate 16 bit values rather than device sniffing. You could start with the web safe colour palette.

或者,如果用户认为看起来更好,可以选择使用灰度 - 您也可以找到其他用户选择该选项。如果您的颜色都是基于类的颜色,您可以替换当前样式表或添加具有适当重新分配颜色的新样式表。

Alternatively, give users an option to "use greyscale" if they think that will look better—you may find other users selecting that option too. If your colours are all class based, you could either replace a current stylesheet or add a new one with appropriately reassigned colours.

这篇关于Javascript:检测单色显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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