我想用delphi将RGB转换为HSL,我的代码:
uses
System.UIConsts;
procedure TForm1.Button3Click(Sender: TObject);
var
H, S, L: Single;
begin
var R := 157;
var G := 157;
var B := 152;
var alc := MakeColor(R, G, B, 255);
RGBtoHSL(alc, H, S, L);
//FROM: https://www.rapidtables.com/convert/color/rgb-to-hsl.html
//HSL: 60,2.5,60.6 <--correct Value
ShowMessage(Format('HSL: %.1f,%.1f,%.1f', [H, S * 100, L * 100])); //<---wrong Hue's value
end;
如何获得正确的色调值? 谢谢。
看起来
UIConsts.RGBtoHSL
函数将颜色的色调表示为 0 到 1 之间的实数。如果您需要 0 到 360 之间的值,则需要缩放 360 倍:
Format('HSL: %.1f,%.1f,%.1f', [360 * H, S * 100, L * 100])