Archived

This topic is now archived and is closed to further replies.

DelphiX colors

This topic is 5672 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Can anyone tell me why this code fills the area with red ? lArea: TRect; ................ DXDraw1.Surface.Canvas; DXDraw1.Surface.Canvas.Brush.Color := clRed; DXDraw1.Surface.Canvas.FillRect(Rect1); .. and this one with blue ? DXDraw1.Surface.FillRect(Rect1,clRed); Thanks / Tommy

Share this post


Link to post
Share on other sites
I had the same problem a while back, this solved it..


{ 16 Bit green dominant }
function _RGB565(r, g, b : byte): integer;
begin
Result := ((b mod 32) + ((g mod 64) shl 6) + ((r mod 32) shl 11));
end;

{ 16 Bit }
function _RGB555(r, g, b : byte): integer;
begin
Result := ((b mod 32) + ((g mod 32) shl 5) + ((r mod 32) shl 10));
end;





Just punch in your RGB values and all will be well

As turbo said colour match will work, but on my computer its really slow, you could cache the values you get from colour match or make a new set of colour constants using values colourmatch returns which would prevent using these two functions I provided or this matching routine.

What colourmatch actually does is create an offscreen DIB, draws the colour you want to it as a single pixel, then the blitting code 'rounds' the colour up to the required depth for the pixel, then the value is queried for this pixel, which is the colour which will actually work on your 16bit surface, and the DIB is freed.

The reason your 32bit colour(clRed) works using the canvas is that the GDI automatically converts the colour(correctly) to 16bit mode. So on saying that with a 32bit surface you should be ok using these colour constants.

Afterword:
Both functions were taken from TOTWGPG page 290

[edited by - Zanthos on June 5, 2002 7:31:46 AM]

Share this post


Link to post
Share on other sites