delphi RGB 转 HSV
1 procedure RgbToHsv(R, G, B: Byte; var H, S, V: Single); 2 var 3 mx, mn: Byte; 4 tmp: Single; 5 begin 6 mx := R; 7 mn := R; 8 if mx < G then mx := G; 9 if mx < B then mx := B; 10 if mn > G then mn := G; 11 if mn > B then mn := B; 12 if mx = 0 then 13 begin 14 H := -1; S := 0; V := 0; 15 Exit; 16 end; 17 18 V := mx / 255; 19 S := (mx - mn) / mx ; 20 tmp := 60.0 / (mx - mn); 21 if mx = R then H := (G - B) * tmp 22 else if mx = G then H := 120 + (B - R) * tmp 23 else if mx = B then H := 240 + (R - G) * tmp; 24 if H < 0 then H := H + 360; 25 end;