我使用以下代码进行 RGB 模型到 HSB 模型的转换,反之亦然:
procedure HSVToRGB(Const H, S, V: Single; Out R, G, B: Single);
const
SectionSize = 60/360;
var
F: single;
P, Q, T: single;
Section: single;
SectionIndex: integer;
begin
if H < 0 then
begin
R:= V;
G:= R;
B:= R;
end
else
begin
Section:= H/SectionSize;
SectionIndex:= Floor(Section);
F:= Section - SectionIndex;
P:= V * ( 1 - S );
Q:= V * ( 1 - S * F );
T:= V * ( 1 - S * ( 1 - F ) );
case SectionIndex of
0:
begin
R:= V;
G:= T;
B:= P;
end;
1:
begin
R:= Q;
G:= V;
B:= P;
end;
2:
begin
R:= P;
G:= V;
B:= T;
end;
3:
begin
R:= P;
G:= Q;
B:= V;
end;
4:
begin
R:= T;
G:= P;
B:= V;
end;
else
begin
R:= V;
G:= P;
B:= Q;
end;
end;
end;
end;
procedure RGBToHSV(Const R, G, B: Single; Out H, S, V: Single);
var
Range: single;
RGB: array[0..2] of single;
MinIndex, MaxIndex: integer;
begin
RGB[0]:= R;
RGB[1]:= G;
RGB[2]:= B;
MinIndex:= 0;
if G < R then MinIndex:= 1;
if B < RGB[MinIndex] then MinIndex:= 2;
MaxIndex:= 0;
if G > R then MaxIndex:= 1;
if B > RGB[MaxIndex] then MaxIndex:= 2;
Range:= RGB[MaxIndex] - RGB[MinIndex];
if Range = 0 then
begin
H:= -1;
S:= 0;
V:= R;
end
else
begin
case MaxIndex of
0:
begin
H:= (G-B)/Range;
end;
1:
begin
H:= 2 + (B-R)/Range;
end;
2:
begin
H:= 4 + (R-G)/Range;
end;
end;
S:= Range/RGB[MaxIndex];
V:= RGB[MaxIndex];
H:= H * (1/6);
if H < 0 then H:= 1 + H;
end;
end;
并且还使用David Heffernan 的代码**进行 HSV 模型到 RGB 模型的转换。
我的要求是读取Label02.Color
. Adobe Specification
然后根据(即 H = 0 <-> 360,S = 0 <-> 100,V = 0 <-> 100)将其转换为 HSV 值。然后更改 HSV 值。之后,只有将V Value
继续使用。Increased
Decreased
Timer03
所以我也写了以下代码:
procedure TMainForm.Timer03Timer(Sender: TObject);
var
HueOfColor, SaturationOfColor, BrightnessOfColor: single;
RedColor, GreenColor, BlueColor: integer;
begin
RedColor := ColorToRGB(GetRValue(Label02.Font.Color));
GreenColor := ColorToRGB(GetGValue(Label02.Font.Color));
BlueColor := ColorToRGB(GetBValue(Label02.Font.Color));
end;
我无法转换它们,RGBToHSV Procedure
因为它是基数。所以我也无法更改V Value
. 另一件事是,根据Adobe Photoshop
is S Value
between0-100
但在这里和在您的解决方案中也是如此0-1
。所以我想我必须乘以S Value
100 或除以S Value
100。