我正在研究此 post 的最后一个答案中的示例代码
看看如何制作一个好的闪烁按钮。该示例代码使用以下代码来指定颜色:
for (int i = 0; i < N; i++)
{
clut.add(Color.getHSBColor(1, 1 - (i / N), 1));
}
for (int i = 0; i < N; i++)
{
clut.add(Color.getHSBColor(1, i / N, 1));
}
Color.getHSBColor(1, 1 - (i/N), 1) 是构建颜色的地方。 getHSBColor() 的第一个参数 (Hue) 将指定基色。因此,如果我将其更改为230,则颜色应该是基于蓝色的颜色;如果是60,则颜色应基于黄色。但示例程序并没有按照我的预期工作。将色相设置为不同的值后,没有闪烁的颜色变化。有人知道为什么吗?
最佳答案
Color.getHSBColor()
应接收从 0 到 1 的 float ,因此任何大于 1 的值都将被视为 1...
看一下:
The hue parameter is a decimal number between 0.0 and 1.0 which indicates the hue of the color. You'll have to experiment with the hue number to find out what color it represents.
For example, setPenColor(Color.getHSBColor(0.56f, 1.0f, 0.8f));
来源:http://www.otherwise.com/Lessons/ColorsInJava.html
例如,您可以这样做:
float hue = your_color/255; // if you want to use 0-255 range
for (int i = 0; i < N; i++) {
clut.add(Color.getHSBColor(hue, 1 - (i / N), 1));
}
for (int i = 0; i < N; i++) {
clut.add(Color.getHSBColor(hue, i / N, 1));
}
关于java - 如何更改HSB颜色系统中的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7488117/