How to realize a palette

  • Thread starter Thread starter Just Me
  • Start date Start date
J

Just Me

I asked this in the VB NG and didn't get a response. I think this NG is no
apt to know this kind of thing so I'm trying here.

Trying to display the palette that is on the clipboard.

I get a palette from the clipboard and I want to make the picturebox display
it and realize it as its palette.

Actually the picturebox is on a usercontrol which is on the form containing
this code.

I get the palette OK and draw it but the colors are dithered so I assume my
attempt to realize it failed.

Any help would be appreciated



lHDataPalette = User.GetClipboardData(CF_PALETTE)

lNumDataPaletteEntries = GDI.GetPaletteEntries(lHDataPalette, 0, 256,
lDataLogPal.palPalEntry)

User.CloseClipboard()

If lNumDataPaletteEntries <> 0 Then

Dim lHDataPal As IntPtr

Dim lHPrevPal As IntPtr

Dim lHDCPic As IntPtr

lDataLogPal.palVersion = &H300S

lDataLogPal.palNumEntries = 256

lHDCPic = User.GetDC(ControlPicture1.PicHandle)

lHDataPal = GDI.CreatePalette(lDataLogPal)

lHPrevPal = GDI.SelectPalette(lHDCPic, lHDataPal, 0)

GDI.RealizePalette(lHDCPic)

lHDataPal = GDI.SelectPalette(lHDCPic, lHPrevPal, 0)

User.ReleaseDC(Handle, lHDCPic)

GDI.DeleteObject(lHDataPal)
 
Just Me said:
I asked this in the VB NG and didn't get a response. I think this NG is no
apt to know this kind of thing so I'm trying here.

Trying to display the palette that is on the clipboard.

I am not sure what you are after.
I have a program available that displays all MS colours
and a program with which you can mix colours.
I would be happy to post them to you.
 
I'd like to see them as an educational tool.
But I want to display a palette from the clipboard.
I can get it and draw the colors but since the colors do not match the
screens palette they are dithered.
I'd like to make the picturebox use the palette I got from the clipboard.
I think the code I gave is close but doesn't seem to remove the dither -
like maybe the palette I tried to realize didn't take effect.


Thanks
 
I don't know if this is possible. Before I investigate further would you
tell me why you need to do this? If you're running .NET I would have thought
that a machine that handles more than 256 colours is pretty much a
prerequisite?

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
In photshop you can develop for indexed 256 colors and coping to the
clipboard puts a palette there.
I want to display it.

BTW; While testing I put my display into 256 color mode and XP works find.

Maybe I just don't understand but I'd guess that if I realize a palette in
the picturebox HDC I should be able to display all those colors in the
picturebox without dithering.

Thanks for the interest
 
Back
Top