Question

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++.

Was it helpful?

Solution

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;
    };
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top