Board index » delphi » RGB Value to Hex

RGB Value to Hex

Does anyone know how to convert an RGB value to hex?  The RGB values are all
together (from ColorToRGB funtion).  So, I need to separate them into red,
green, and blue values and then convert them to hex.

Thanks,
Scott

 

Re:RGB Value to Hex


Quote
Scott Hathaway wrote:

> Does anyone know how to convert an RGB value to hex?  The RGB values are all
> together (from ColorToRGB funtion).  So, I need to separate them into red,
> green, and blue values and then convert them to hex.

Given a RGB value, you get
  red :=    RGB and $FF;
  green :=  (RGB shr 8) and $FF;
  blue :=   (RGB shr 16) and $FF;

HTH
-Michael

Re:RGB Value to Hex


Scott,

Here's one way...
Use ColorToRGB to convert a Delphi TColor value to a Windows RGB value then
use the API functions GetRValue, GetGValue and GetBValue to get the
corresponding integer values and convert to hex.

--
Stephen Brown

Quote
Scott Hathaway <slh...@flash.net.1> wrote in message

news:82vE3.215$Nk5.306@news.flash.net...
Quote
> Does anyone know how to convert an RGB value to hex?  The RGB values are
all
> together (from ColorToRGB funtion).  So, I need to separate them into red,
> green, and blue values and then convert them to hex.

Re:RGB Value to Hex


Thanks!

Quote
Stephen Brown wrote in message <7rue4v$d6...@gxsn.com>...
>Scott,

>Here's one way...
>Use ColorToRGB to convert a Delphi TColor value to a Windows RGB value then
>use the API functions GetRValue, GetGValue and GetBValue to get the
>corresponding integer values and convert to hex.

>--
>Stephen Brown

>Scott Hathaway <slh...@flash.net.1> wrote in message
>news:82vE3.215$Nk5.306@news.flash.net...
>> Does anyone know how to convert an RGB value to hex?  The RGB values are
>all
>> together (from ColorToRGB funtion).  So, I need to separate them into
red,
>> green, and blue values and then convert them to hex.

Other Threads