PDA

View Full Version : ColorToRGB in 16 bits TColor



kotai
09-03-2007, 05:00 PM
Hi

I need convert a 16bits color to RGB.

I have this code:

ColorPixel := DXImageList.Items[1].PatternSurfaces[0].Pixel[X,Y];
R := GetRValue(ColorPixel);
G := GetGValue(ColorPixel);
B := GetBValue(ColorPixel);


ColorPixel := ColorToRGB(DXImageList.Items[1].PatternSurfaces[0].Pixel[X,Y]); --> same results.


if Windows are in 32bits color work fine, but when Windows are in 16bits color not work fine, Blue always is 0 and Red and Green ara more value:

Example:
in 32 bits color one pixel:
Results:
ColorPixel = 9005609 --> 896A29
R = 41 --> 29
G = 106 --> 6A
B = 137 --> 89

in 16 bits color (same pixel)
Results:
ColorPixel = 35653 --> 8B45
R = 69
G = 139
B = 0

Can I convert 16 bits color to 24 bits color ?

Thanks

kotai
09-03-2007, 06:46 PM
Solved:

function RGBTo16bit(R,G,B: Byte): Integer;
begin
Result:= ((B shr 3) shl 11) + ((G shr 2) shl 5) + (R shr 3);
end;


function ToRGB(Color: Integer): Integer;
begin
Result:= ((Color and $F800) shl 8) + ((Color and $7E0) shl 5) +
((Color and $1F) shl 3)
end;

Kotai. :roll:

JernejL
10-03-2007, 07:57 AM
In 16 bit there's even a 5551 (1 bit alpha) format, you need code for that one ?

kotai
10-03-2007, 11:05 AM
No, thanks work fine.

6 bits for green and 5 for red and blue.

Kotai. :roll: