Android 改变颜色的亮度
我想改变任何给定颜色的亮度(注意:我不是在谈论屏幕亮度),我已经查看了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最简单的方法是将颜色转换为 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.
考虑到您正在谈论亮度(颜色增强)而不是亮度(白色量),您的模型是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.
对于初学者,您需要记住两件事 -
For starters, you need to remember two things -
您可以使用
颜色。 colorToHSV
将颜色转换为 HSV,然后更改 HSV 颜色的亮度,然后使用Color.HSVToColor
将其转换回颜色 int。例如,以下代码将亮度设置为 0.5:You can use
Color.colorToHSV
to convert the color to HSV, then change the brightness of the HSV color, then useColor.HSVToColor
to convert it back to a color int. For example, the following code sets the brightness to 0.5: