Board index » delphi » Color properties: how can I use color from custom 256 color palette

Color properties: how can I use color from custom 256 color palette

When I'm using a custom 256 color palette, based on the standard windows
256 color palette, is it possible to use a specific color for the color
property for a standard component (e.g. Memo1.Color:= MyColor).

Now windows is adjusting at runtime MyColor by dithering and that's very
ugly. I just want to have a solid background color.

Does anyone knows how to overcome this problem ?

Thanx in advance.

 

Re:Color properties: how can I use color from custom 256 color palette


M. -

First, Windows does not have a "standard 256 color palette". When
you're running in 256 color mode, the only colors you can be assured
of are the ten at the top and the ten at the bottom of the palette.

To use any non-standard color (those not in the first or last ten) you
have to do the drawing yourself - first by creating a palette with the
colors you want, then by selecting it into your device context
(Canvas.Handle), realizing it and then you can finally reference that
color.

In the case of a TMemo, you'd want to use a descendant that responds
to the WM_ERASEBKGND message.

Good luck.

Kurt

Re:Color properties: how can I use color from custom 256 color palette


Quote
Kurt Barthelmess (TeamB) wrote:

> M. -

> First, Windows does not have a "standard 256 color palette". When
> you're running in 256 color mode, the only colors you can be assured
> of are the ten at the top and the ten at the bottom of the palette.

> To use any non-standard color (those not in the first or last ten) you
> have to do the drawing yourself - first by creating a palette with the
> colors you want, then by selecting it into your device context
> (Canvas.Handle), realizing it and then you can finally reference that
> color.

> In the case of a TMemo, you'd want to use a descendant that responds
> to the WM_ERASEBKGND message.

> Good luck.

> Kurt

Hi Kurt,

Thank you for your quick response. I've tried the following code and
it's not working. Can you help me out ?

procedure TForm1.FormCreate(Sender: TObject);
var
  DC: HDC;
begin
  DC:= GetDC(Form1.Canvas.Handle);
  SelectPalette(DC, MyImage.Picture.Bitmap.Palette, True); {MyImage
contains the color cyan 15 %}
  RealizePalette(DC);
  Form1.Color:= $01FBF0DF; {cyan 15 %}
end;

The resulting formcolor is a dittered color. This is not what I had in
mind. Do you know how to get a solid color ? Thank you in advance.

Monica Goorden

Re:Color properties: how can I use color from custom 256 color palette


Monica -

Try using $02 for the first byte of the color you want. Of course, it
must be in the palette.

Now there are a few other problems here - You're getting your own DC,
so you have to draw on that rather than Canvas. You don't seem to be
releasing the DC, sp, you'll have roughly three shots at drawing
before your system crashes.

Good luck.

Kurt

Other Threads