Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ColorToRGB function equivalent in Firemonkey

Does there exist an equivalent function in FMX for ColorToRGB?

like image 343
cadetill Avatar asked Nov 14 '12 11:11

cadetill


1 Answers

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;
like image 118
sergeantKK Avatar answered Sep 30 '22 08:09

sergeantKK