Click to See Complete Forum and Search --> : Using palettes


December 17th, 1999, 06:50 AM
I am programming an application that needs a palette filled with shades of red.
I have tried the following lines of code :

For i = 0 To 255
Pal.palPalEntry(i).peRed = i
Pal.palPalEntry(i).peGreen = 0
Pal.palPalEntry(i).peBlue = 0
Pal.palPalEntry(i).peFlags = 0
Next i
hPal = CreatePalette(Pal)
hHoldPrevPal = SelectPalette(Form1.hdc, hPal, True)
RealizePalette (Form1.hdc)

RealizePalette has returned a value of 249.
While trying all shades of red, from RGB(0,0,0) to RGB(255,0,0) , I could get only 4 distinct shades of red,
with all the others dithered.

Thanks for any help,
Gino.

Feng Yuan
December 17th, 1999, 03:17 PM
That is correct.

You should use SelectPalette(Form1.hdc, hPal, False) to set the palette as foreground palette. Only foreground palette can force other colors out of system palette.

With foreground palette, you may get 236+3 levels of red shade.

A C/C++ programmer