FMX中是否存在ColorToRGB
的等效功能?
答案 0 :(得分:7)
您可以使用TAlphaColorRec获取R,G,B或longint值(在Delphi XE3 + FireMonkey2中 - 我不确定XE2)
试试这个,将两个按钮和一个TRectangle添加到Firemonkey表单中,并为onClick事件添加这些按钮:
procedure TForm1.btnBrownClick(Sender: TObject);
var
r: System.Byte;
aColor: TAlphaColor;
rgbValue: longint;
begin
aColor:= TAlphaColorRec.Brown; //$A52A2A
r:= TAlphaColorRec(aColor).R;
ShowMessage('Red component of Brown is: $'+IntToHex(r,2));
Rectangle1.Fill.Color:= aColor;
rgbValue:= TAlphaColorRec(aColor).Color;
ShowMessage('Brown is: $'+IntToHex(rgbValue,8));
end;
procedure TForm1.btnRedderClick(Sender: TObject);
var
aColor: TAlphaColor;
rgbValue: longint;
begin
aColor:= TAlphaColorRec.Brown;
TAlphaColorRec(aColor).R:= 255; //$A52A2A becomes $FF2A2A
Rectangle1.Fill.Color:= aColor;
rgbValue:= TAlphaColorRec(aColor).Color;
ShowMessage('Redder Brown is: $'+IntToHex(rgbValue,8));
end;