如何查看 RGB 颜色是否太浅
我有一个应用程序,其中客户选择颜色。 我不能让这个颜色太浅。 有没有办法看到这一点,防止客户选择太浅的颜色?
非常感谢!
太亮的情况下颜色几乎是白色......我有一个白色背景的网站,用户可以通过 jquery 插件选择颜色。
我想让用户选择他想要的颜色,但不能太浅。
I have an aplication in which the customer chooses a color.
I can't let this color be too light.
Is there a way to see this, to prevent the customer from chosing a color that is too light?
Thank you a lot!
too light in the case is a color almost white....i have a web site with a white background and the user can choose a color through a jquery plugin.
I want to allow the user to choose the color he wants, but cant be too light.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您正在寻找对比度,那么查看这篇文章。
他们展示了一个类似这样的函数,可以根据任意颜色选择文本颜色:
如果颜色太浅,以至于无法在该颜色之上读取白色文本,则上述函数将返回 true。
If contrast is what you are looking for then check out this article.
They show a function like this to choose text color based on any arbitrary color:
The above function will return true if the color is too light for white text to be readable on top of this color.
“太轻”相对于什么?一些图像?纯白色?一些灰色阴影?最简单的方法是确保 R、G、B 成员值之一高于某个阈值,尽管如果用户选择 (128,0,0) 并将其粘贴到 (127 ,0,0) - 差异为 (1,0,0) 并且在大多数显示器上是不可见的或至少几乎不可能发现。
'too light' relative to what? Some image? pure white? some shade of grey? Easiest method is to just make sure that one of the R,G,B member values is above some threshold, though that won't help if the user selects (128,0,0) and it's being pasted onto an image that's (127,0,0) - the difference is (1,0,0) and would be invisible or at minimum almost impossible to spot on most monitors.
您并不太具体,但假设您使用的是 Javascript,
var v = Math.round((r+g+b)/3)
并检查它是否低于某个阈值?另外,颜色是什么形式? RGB? HSL?十六进制?
You're not being too specific, but assuming you are using Javascript,
var v = Math.round((r+g+b)/3)
and check that it is below a certain threshold?Also, what form is the color in? RGB? HSL? Hex?