在网上找转换算法无非那一两个,而且原理相同。在测试过程中发现在s和l同取1的时候,得到的结果是(255,255,255)白色,别的时候基本正确,只需要再加一个判断即可,可是对转换原理知之甚少,不知道该怎么做,请高手帮助解决。 procedure HSL2RGB(H, S, L:Double; var R, G, B: integer);
var
mx, mn: Double;
function f(h, mx, mn: Double): double;
begin
f:=0;
if h<0 then h:=h+360;
if h>=360 then h:=h-360;
if (h>=0) and (h<60) then
f := mn+(mx-mn)*h/60
else if (h>=60) and (h<180) then
f := mx
else if (h>=180) and (h<240) then
f := mn+(mx-mn)*(240-h)/60
else if (h>=240) then
f := mn
// h not between 0~360 !!
else ShowMessage('h= '+FloatToStr(h)+' error!');
end;
begin
if L <=0.5 then
begin
mx := L * (1+S);
mn := 2*L-mx;
end
else
begin
mx := L*(1-S)+S;
mn := 2*L-mx;
end; R := floor(f(H+120, mx, mn));
G := floor(f(H, mx, mn));
B := floor(f(H-120, mx, mn));
// Retrieve R, G, B from H, S, L
end;
var
mx, mn: Double;
function f(h, mx, mn: Double): double;
begin
f:=0;
if h<0 then h:=h+360;
if h>=360 then h:=h-360;
if (h>=0) and (h<60) then
f := mn+(mx-mn)*h/60
else if (h>=60) and (h<180) then
f := mx
else if (h>=180) and (h<240) then
f := mn+(mx-mn)*(240-h)/60
else if (h>=240) then
f := mn
// h not between 0~360 !!
else ShowMessage('h= '+FloatToStr(h)+' error!');
end;
begin
if L <=0.5 then
begin
mx := L * (1+S);
mn := 2*L-mx;
end
else
begin
mx := L*(1-S)+S;
mn := 2*L-mx;
end; R := floor(f(H+120, mx, mn));
G := floor(f(H, mx, mn));
B := floor(f(H-120, mx, mn));
// Retrieve R, G, B from H, S, L
end;
解决方案 »
- adoquery readonly ......?
- delphi如何调用脚本?
- function setedit_backcolor(formname:Tform):string;调用时报错?
- 想请教高手skinengine如何安装?
- pas调用dll里的函数比调用该pas里面的函数时间长吗?
- help,help,sql!!!
- 请问谁有抽奖的原码?希望有一次能抽出多号码的,如200……
- Table(超级难)100分。
- 关于object pascal初学者
- dbgrid的oncellclick事件问题。(在线等)
- 发现hsl转rgb算法中的大问题,请教该如何解决!!!!!!!!!!!!!!!!
- 问一个关于COM的问题
不同的色彩空间用于不同的领域,能够表示的颜色范围也不一样