Color.RGBtoHSB(int r,int g,int b,float[] hsv)
r : 紅色值
g : 綠色值
b : 藍色值
hsv : hue, saturation, and brightness array
範例程式碼如下(將紅色轉成HSV):
import java.awt.Color; public class Example { public static void main(String[] args) { int r=255; int g=0; int b=0; float hsv[]=rgb2HSV(r,g,b); System.out.println(hsv[0]+" "+hsv[1]+" "+hsv[2]); } public static float[] rgb2HSV (int r,int g, int b) { float[] hsv = new float[3]; Color.RGBtoHSB(r,g,b,hsv); return hsv; }
執行結果
0.0 1.0 1.0
參考來源:
http://docs.oracle.com/javase/1.5.0/docs/api/java/awt/Color.html#RGBtoHSB%28int,%20int,%20int,%20float%5b%5d%29
http://stackoverflow.com/questions/2399150/convert-rgb-value-to-hsv
沒有留言:
張貼留言