如何查看 RGB 颜色是否太浅

发布于 2024-10-27 17:24:09 字数 171 浏览 3 评论 0原文

我有一个应用程序,其中客户选择颜色。 我不能让这个颜色太浅。 有没有办法看到这一点,防止客户选择太浅的颜色?

非常感谢!


太亮的情况下颜色几乎是白色......我有一个白色背景的网站,用户可以通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌梦深 2024-11-03 17:24:09

如果您正在寻找对比度,那么查看这篇文章

他们展示了一个类似这样的函数,可以根据任意颜色选择文本颜色:

function isTooLightYIQ(hexcolor){
  var r = parseInt(hexcolor.substr(0,2),16);
  var g = parseInt(hexcolor.substr(2,2),16);
  var b = parseInt(hexcolor.substr(4,2),16);
  var yiq = ((r*299)+(g*587)+(b*114))/1000;
  return yiq >= 128;
}

// usage:
element.style.color = isTooLightYIQ('ff0045') ? '#000' : '#fff';

如果颜色太浅,以至于无法在该颜色之上读取白色文本,则上述函数将返回 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:

function isTooLightYIQ(hexcolor){
  var r = parseInt(hexcolor.substr(0,2),16);
  var g = parseInt(hexcolor.substr(2,2),16);
  var b = parseInt(hexcolor.substr(4,2),16);
  var yiq = ((r*299)+(g*587)+(b*114))/1000;
  return yiq >= 128;
}

// usage:
element.style.color = isTooLightYIQ('ff0045') ? '#000' : '#fff';

The above function will return true if the color is too light for white text to be readable on top of this color.

她如夕阳 2024-11-03 17:24:09

“太轻”相对于什么?一些图像?纯白色?一些灰色阴影?最简单的方法是确保 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.

默嘫て 2024-11-03 17:24:09

您并不太具体,但假设您使用的是 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文