Original Post
I'm using Delphi 5 (just moved over from VB6 after a month of learning to program badly).
Does anyone know how to easily break down the color values returned in a COLORREF type into the RGB components?
Mathematically I understand the process:
RGBval [IntegerDiv] 256^(RGBComp - 1) and 255
where RGBComp is the component you're looking for (i.e. 1 is Red, 2 is Green, 3 is blue etc...)
I also know that in Delphi ^ is used as a pointer function so I'm using the Power function in the math unit.
However the compiler keeps whining about my first [If] line and on the second line it won't do the bitwise operator...[
]
Here's the function:
function DecodePixel(RGBval : COLORREF; RGBComp : Integer) : Integer;
begin
If RGBComp > 0 And RGBComp < 4 And RGBval >= 0 And RGBval < 16777216 Then
DecodePixel := RGBval div Power(256, (RGBComp - 1)) and 255
Else
DecodePixel := -1;
end;
end.
[edited by - g_fire_1983 on April 14, 2002 11:16:06 AM]