在网上找转换算法无非那一两个,而且原理相同。在测试过程中发现在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;