5

FMX 中是否存在等效功能ColorToRGB

4

1 回答 1

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;
于 2012-11-14T14:15:03.763 回答