cadetill
cadetill

Reputation: 1552

ColorToRGB function equivalent in Firemonkey

Does there exist an equivalent function in FMX for ColorToRGB?

Upvotes: 4

Views: 6451

Answers (1)

sergeantKK
sergeantKK

Reputation: 614

You can use TAlphaColorRec to get R,G,B or longint values (in Delphi XE3+FireMonkey2 - I'm not sure about XE2)

Try this, add two buttons and a TRectangle to a Firemonkey form and add these for the onClick events:

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;

Upvotes: 7

Related Questions