在java中将深色变为亮色

时间:2017-04-16 03:51:49

标签: java colors

我正在开发一个程序,我从图像的一部分中获取RGB值。我想去除颜色中的黑暗并使其变亮。我的工作是使用<?php echo system("echo 'm' > /dev/ttyAMA0"); sleep(2); echo system("echo '1' > /dev/ttyAMA0"); sleep(2); echo system("echo '2' > /dev/ttyAMA0"); sleep(2); echo system("echo '3' > /dev/ttyAMA0"); sleep(2); echo system("echo '4' > /dev/ttyAMA0"); sleep(2); echo system("echo '5' > /dev/ttyAMA0"); sleep(2); echo system("echo '6' > /dev/ttyAMA0"); ?> 然后我使用亮度通道并将其设置为范围内的最高值,然后将HSB转换回RGB。但是,当我这样做时,颜色会完全改变。这是一个深红色的示例,它变成紫色,我用这个代码。

Color.RGBtoHSB

输出:

System.out.println("Before Conversion:");
System.out.println("R: " + rAvg  + "\nG :" + gAvg + "\nB :" + bAvg);
Color.RGBtoHSB(rAvg, gAvg, bAvg, hsv);

hsv[2] = 100; //Set to max value
System.out.println("H: " + hsv[0] * 360 + "\nS: " +  hsv[1] * 100 + "\nV :" + hsv[2]);

int rgb = Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]);
System.out.println("After conversion");
Color color = new Color(rgb);
System.out.println("R: " + color.getRed());
System.out.println("G: " + color.getGreen());
System.out.println("B: " + color.getBlue());

1 个答案:

答案 0 :(得分:2)

亮度hsv[2]需要是介于0和1之间的值。尝试以下两行代码:

    hsv[2] = 1; //Set to max value
    System.out.println("H: " + hsv[0] * 360 + "\nS: " +  hsv[1] * 100 + "\nV :" + hsv[2] * 100);