|
Converting RGB colors into values of hue saturation and intensity |
|
|
This Java tip contains a program which converts given red, green and blue values
(RGB Color Space) into corresponding hue, saturation and intensity values (HSI Color Space).
import java.awt.Color;
import java.io.PrintStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class RGB2HSIConverter
{
public RGB2HSIConverter()
{
}
public static void main(String args[])
{
if(args.length > 2)
{
int ai[] = new int[3];
for(int i = 0; i < 3; i++)
ai[i] = Integer.parseInt(args[i]);
float af[] = Color.RGBtoHSB(ai[0], ai[1], ai[2], null);
String args1[] = {
"H=", "S=", "I="
};
DecimalFormat decimalformat = new DecimalFormat("0.000");
for(int j = 0; j < 3; j++)
System.out.println(args1[j] + decimalformat.format(af[j]));
} else
{
System.err.println("usage: java RGB2HSIConverter <r> <g> <b>");
System.exit(1);
}
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.