- 亮度對比度,
- 的亮度差,和
- 的差在顏色
兩個給定的顏色之間?
實施例:
輸入
- 顏色1:#99CCFF
- 顏色2:#225588
輸出
- 光度對比度:4.57:1的亮度
- 差:在顏色119
- 差:357
兩個給定的顏色之間?
實施例:
輸入
輸出
從轉換各顏色(R,G,B)到(H,S, V)[或(H,S,L)]座標。你可以找到公式at Wikipedia。
我已經寫帕斯卡爾功能如下:
function RGBToHSV(const Color: TRGB): THSV;
var
cmax, cmin, cdiff: real;
begin
cmax := MaxComponent(Color);
cmin := MinComponent(Color);
cdiff := cmax - cmin;
with Color, result do
begin
// Hue
if cmax = cmin then
hsvHue := 0
else if cmax = rgbRed then
hsvHue := (60 * (rgbGreen - rgbBlue)/cdiff)
else if cmax = rgbGreen then
hsvHue := (60 * (rgbBlue - rgbRed)/cdiff) + 120
else
hsvHue := (60 * (rgbRed - rgbGreen)/cdiff) + 240;
hsvHue := Fix360(hsvHue);
// Saturation
if cmax = 0 then
hsvSaturation := 0
else
hsvSaturation := 1 - cmin/cmax;
// Value
hsvValue := cmax;
end;
end;
function RGBToHSL(const Color: TRGB): THSL;
var
cmax, cmin, cdiff, csum: real;
begin
cmax := MaxComponent(Color);
cmin := MinComponent(Color);
cdiff := cmax - cmin;
csum := cmax + cmin;
with Color, result do
begin
// Hue
if cmax = cmin then
hslHue := 0
else if cmax = rgbRed then
hslHue := (60 * (rgbGreen - rgbBlue)/cdiff)
else if cmax = rgbGreen then
hslHue := (60 * (rgbBlue - rgbRed)/cdiff) + 120
else
hslHue := (60 * (rgbRed - rgbGreen)/cdiff) + 240;
hslHue := Fix360(hslHue);
// Saturation
if cmax = cmin then
hslSaturation := 0
else if csum <= 1 then
hslSaturation := cdiff/csum
else
hslSaturation := cdiff/(2 - csum);
// Lightness
hslLightness := csum/2;
end;
end;
我好像記得是這樣的((red_value1 * 299 + green_value1 * 587 + blue_value1 * 114)/(red_value2 * 299 + green_value2 * 587 + blue_value2 * 114)) – 2011-06-10 14:51:01
@ anirudh4444:對於我的示例,結果是2.57490315 ...看起來不像任何預期的輸出。這應該算什麼?任何想法,這些神奇的數字來自哪裏? – Shawn 2011-06-10 15:14:54