Android 改变颜色的亮度

发布于 2024-10-10 02:04:16 字数 144 浏览 0 评论 0原文

我想改变任何给定颜色的亮度(注意:我不是在谈论屏幕亮度),我已经查看了 Color 类,它有一些用于 RGB 和 HSV 之间转换的方法,我我是这个领域的新手。首先,如果红色的值以 RGB (#FF0000) 指定,我该如何更改红色的亮度?

I want to change the brightness of any given color (Note: I am not talking about screen brightness), I have looked at the Color class, it has a few methods for conversions between RGB and HSV, I'm a newbie in this area. To start with, how do I change the brightness of red, if its value is spefied in RGB (#FF0000)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

十二 2024-10-17 02:04:16

最简单的方法是将颜色转换为 HSL(不是 HSV!它们是不同的 - 请参阅 http://en .wikipedia.org/wiki/HSL_and_HSV)并更改 L 分量 - 增加使其更亮,减少使其更暗。

The easiest way would be to convert the color to HSL (not HSV! they are different - see http://en.wikipedia.org/wiki/HSL_and_HSV) and change the L component - increase to make it brighter, decrease to make it darker.

愿得七秒忆 2024-10-17 02:04:16

考虑到您正在谈论亮度(颜色增强)而不是亮度(白色量),您的模型是HSV(又名HSB)而不是HSL。

在快速简报中,如果你增强 HSV 上的 V 通道,比如说……一些蓝色,你就会有一个“更蓝”的颜色。如果增强 HSL 模型上的 L 通道,您将获得更“清晰且水洗”的蓝色。

android.graphics.Color 类内置了对 HSV 模型的支持。使用 Color.colorToHSV()Color.HSVToColor() 编辑亮度值(或色调,或饱和度,如果你愿意的话)。

在 HSV 模型上,H(色调)定义基色,S(饱和度)控制灰度量,V 控制亮度。因此,如果同时增强 V 并降低 S,实际上您会获得更高的亮度。

Considering that you are talking about brightness (color enhance) and not luminance (white amount), your model is the HSV (aka HSB) and not HSL.

On fast briefing, if you enhance the V channel on HSV over, lets say... some blue, you have a "more blue" color. If you enhance the L channel on HSL model you have a more "clear and washed" blue.

The android.graphics.Color class have built-in support to HSV model. Use Color.colorToHSV() and Color.HSVToColor() to edit the brightness value (or hue, or saturation, if you like).

On HSV model, H (hue) define the base color, S (saturation) control the amount of gray and V controls the brightness. So, if you enhance V and decrease S at same time, you gets more luminance, in pratice.

骷髅 2024-10-17 02:04:16

对于初学者,您需要记住两件事 -

  1. 要降低亮度,您可以将红色从 #FF0000 更改为 #AA0000 或 #880000 - 基本上减少红色分量。
  2. 您还可以尝试降低不透明度 - 通常您会意识到它比仅仅降低亮度效果更好。

For starters, you need to remember two things -

  1. To reduce brightness, you can change red from #FF0000 to #AA0000 or #880000 - basically reduce the Red component.
  2. You can also try reducing opacity - often you'll realize that it works better than just reducing brightness.
陈甜 2024-10-17 02:04:16

您可以使用 颜色。 colorToHSV 将颜色转换为 HSV,然后更改 HSV 颜色的亮度,然后使用 Color.HSVToColor 将其转换回颜色 int。例如,以下代码将亮度设置为 0.5:

@ColorInt int originalColor = /*your original color*/;
float[] hsv = new float[3];    //Create an array to pass to the colorToHSV function
Color.colorToHSV(originalColor, hsv);    //Put the HSV components in the array created above
hsv[2] = 0.5f;    //Whatever brightness you want to set. 0 is black, 1 is the pure color.
@ColorInt int newColor = Color.HSVToColor(hsv);    //Convert it back to a ColorInt

You can use Color.colorToHSV to convert the color to HSV, then change the brightness of the HSV color, then use Color.HSVToColor to convert it back to a color int. For example, the following code sets the brightness to 0.5:

@ColorInt int originalColor = /*your original color*/;
float[] hsv = new float[3];    //Create an array to pass to the colorToHSV function
Color.colorToHSV(originalColor, hsv);    //Put the HSV components in the array created above
hsv[2] = 0.5f;    //Whatever brightness you want to set. 0 is black, 1 is the pure color.
@ColorInt int newColor = Color.HSVToColor(hsv);    //Convert it back to a ColorInt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文