How can I get the RGB components of a TAlphaColor in C++ Builder XE5 cross-platform?

StackOverflow https://stackoverflow.com/questions/22634737

  •  20-06-2023
  •  | 
  •  

سؤال

I am converting from VCL to Firemonkey (FMX).

I want to get the R, G, or B values in a TAlphaColor variable.

I used to use the function GetRValue (TColor). However, GetRValue is a Windows GDI call.

Is there a way to do this that will work cross-platform (in particular, Windows and Mac)?

I have found examples that seem to do this with Delphi and TAlphaColorRecs, but I am unable to convert the code to C++.

هل كانت مفيدة؟

المحلول

You can use the TAlphaColorRec struct to read out color channels:

TAlphaColorRec acr;
acr.Color = Color;
Byte r = acr.R;
Byte g = acr.G;
// etc.

The important part of this type is the union which is declared like this:

union
{
    struct
    {
        System::Byte B;
        System::Byte G;
        System::Byte R;
        System::Byte A;
    };
    struct
    {
        System::Word HiWord;
        System::Word LoWord;
    };
    struct
    {
        TAlphaColor Color;
    };
};
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top