Board index » cppbuilder » How to Extract RGB from TColor?

How to Extract RGB from TColor?

I'm trying take the Color Property from a panel and extract the RGB values,
which will then be displayed in seperate edit boxes, one each for Red Green
and Blue.  After trying a couple of different methods, I am still having no
luck.

Can anyone help with this?

Thanks,
Lonnie

 

Re:How to Extract RGB from TColor?


Hi Lonnie,

Quote
> I'm trying take the Color Property from a panel and extract the RGB values,
> which will then be displayed in seperate edit boxes, one each for Red Green
> and Blue.  After trying a couple of different methods, I am still having no
> luck.

You can use the API GetRValue(), GetGValue(), and GetBValue() macros to
retrieve the red, green, and blue components of a TColor,
respectively...

    BYTE R = GetRValue(Panel1->Color);
    BYTE G = GetGValue(Panel1->Color);
    BYTE B = GetBValue(Panel1->Color);

each of these values will range from 0 - 255.  

HTH.

->Damon
-------------------------------------
http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>

Re:How to Extract RGB from TColor?


Thanks a million!!!
Quote

> You can use the API GetRValue(), GetGValue(), and GetBValue() macros to
> retrieve the red, green, and blue components of a TColor,
> respectively...

>     BYTE R = GetRValue(Panel1->Color);
>     BYTE G = GetGValue(Panel1->Color);
>     BYTE B = GetBValue(Panel1->Color);

> each of these values will range from 0 - 255.

> HTH.

> ->Damon
> -------------------------------------
> http://bcbcaq.freeservers.com
> Answers to <Commonly Asked Questions>

Re:How to Extract RGB from TColor?


Quote
Damon Chandler wrote:

Should you not use the ColorToRGB() function first?

Quote
> You can use the API GetRValue(), GetGValue(), and GetBValue() macros to
> retrieve the red, green, and blue components of a TColor,
> respectively...

>     BYTE R = GetRValue(Panel1->Color);
>     BYTE G = GetGValue(Panel1->Color);
>     BYTE B = GetBValue(Panel1->Color);

> each of these values will range from 0 - 255.

--
Joe C. Hecht
http://home1.gte.net/joehecht/index.htm

Re:How to Extract RGB from TColor?


Hi Joe,

Quote
> Should you not use the ColorToRGB() function first?

I this case, I don't think it matters since each of the macros only
operates on the lower 3 bytes...

#define GetRValue(rgb)   ((BYTE) (rgb))  
#define GetGValue(rgb)   ((BYTE) (((WORD) (rgb)) >> 8))
#define GetBValue(rgb)   ((BYTE) ((rgb) >> 16))  

Since AFAIK, the only difference between a COLORREF and TColor is the
possible highest-order byte, it should not affect the result.  You're
the graphics guru, you tell me <g>.

->Damon
-------------------------------------
http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>

Re:How to Extract RGB from TColor?


Quote
Damon Chandler wrote:

> Hi Joe,
> > Should you not use the ColorToRGB() function first?

> I this case, I don't think it matters since each of the macros only
> operates on the lower 3 bytes...

> #define GetRValue(rgb)   ((BYTE) (rgb))
> #define GetGValue(rgb)   ((BYTE) (((WORD) (rgb)) >> 8))
> #define GetBValue(rgb)   ((BYTE) ((rgb) >> 16))

> Since AFAIK, the only difference between a COLORREF and TColor is the
> possible highest-order byte, it should not affect the result.  You're
> the graphics guru, you tell me <g>.

I speak the truth, look at the VCL code and ye shall see...

Joe
--
Joe C. Hecht
http://home1.gte.net/joehecht/index.htm

Other Threads