need help on ColorPalette

FreewareFire

Active member
Joined
May 23, 2003
Messages
28
Hi,


i have a question on the ColorPalette with Bitmaps!


exmpl.

Bitmap bmp = new Bitmap(15,15);

bmp.Palette = ... // Here i want to use a Palette from a File!

How do i load the palette?


Could someone help me, thanks!

Or, if its impossible - how do i define my own palette to use it?

THX !!!!
 
could u give me an example? Ive tried a lot of things - but nothing worked! Im confused...


Please help!!!
 
Does the file contain ONLY palette information? Or, do you have another bitmap type of file (BMP, GIF, etc.) and you want to use the palette from that bitmap on this new one?

-Ner
 
No, its a palette file only - like in Jasc PaintShop ... .pal file! I want to use this pal file for the bitmap! Could someone help?
 
As far as I know, you cant load that PAL into any .NET datastructure directly (though Ive never looked).

Normally, those files are very simple in structure - nothing but Red, Green, and Blue values one after another. You can read the whole file into a byte array, loop through and set your bitmaps palette manually. Just a suggestion if you cant find anything else.

-Ner
 
Yeah, that was my 2nd Question. How do i set it manually? Could you give me an exmpl. please? I know the palette values, so i could do it manually. How do i set my own palette? Thx.
 
Please HELP! ColorPalette !

Color NewColor = new Color();

Bitmap TMPbmp = new Bitmap(1,1, PixelFormat.Format16bppRgb565);

NewColor = Color.FromArgb(212,12,35);

ColorPalette[] NewPalette = new ColorPalette[269];

NewPalette[0] = TMPbmp.Palette;

NewPalette[0].Entries.SetValue(NewColor, 0);

TMPbmp.Palette = NewPalette[0];


Thats a simple example for ColorPalette, but i get an error:

Index out of Range! - could someone help me on this??? i need a palette with 269 values! I know the values and had to store them in palette! Please HELP !!! :confused: :confused:
 
You cant use the Format16bpp... format for a palette. The only bitmaps that use a palette (that I know of) are 8 bit indexed. If you change that to Format8bppIndexed instead of Format16bppRgb565 youll have a palette.

Two other notes.

1. Im not sure why you need 269 ColorPalette objects. You only need one for the code you have. Youre not defining the number of colors in the palette - thats built into the ColorPalette object itself. Youre actually defining 269 objects.

2. Its perfectly fine to assign a variable NewPalette (or NewPalette[0] like you are) to TMPbmp.Palette. But its just another reference to the same object (a ColorPalette is a class, not a struct). You get code readability only. You dont need to use:
TMPbmp.Palette = NewPalette[0]
to get the palette updated. Youre always referencing the same palette whether you use TMPbmp.Palette.Entries... or NewPalette[0].Entries...

-nerseus
 
Ok, thats good, but how do i assign the Colors to the palette? I need 269 Colors - not the Objects - so i need a ColorPalette with 269 Colors in it! How do i assign Color for Color?

NewPalette[0].Entries... (The Value for Position in Palette is here?)

Is it right?
 
You cant have a Palette with that many colors. A Palette is a specific object with ONLY 256 colors. The 256 color bitmap contains indexes into the Palette. So if the first pixel is 1, it points to the Palettes color 1, not the actual color of 1 (which would be almost black).

If you want a 16bpp bitmap thats fine, but you dont need a Palette. You can set each pixels color to any value you want. You have 16 bits per pixel (5 red, 5 green and 6 blue maybe, if I remember right) to choose from. While an artist might call the selection of colors a "palette", in computers it means something much more specific.

-Ner
 
Ok, but the prob is, that the Programm needs to know the Color by itself! You mean i have to read each pixel and set each color? Thats a little bit stupid - or isnt it? I mean, if i load a picture in PSP 7 it knows the Color by the Palette! I still cant convert each byte from a file into a color! Because the format of file and the format of palette doesnt match! So i had to Read a Byte, check which value and set Color - i mean, thats impossible - isnt there another way? Have you an exmpl. or an idea? Please post!
 
Maybe you can explain what it is youre trying to do...

Are you wanting to create a new bitmap (new image data as well) that uses the Palette of an existing bitmap? So Bitmap1 is a house, Bitmap2 is a car and you want Bitmap1 to use the palette of Bitmap2? Or maybe something else...?

-Nerseus
 
Not same, but nearly! I need to assign 269 Colors, individual Colors, to a bitmap. This bitmap contains a image from a game (RollerCoaster Tycoon) - RCT! RCT uses a own specification of Colors! Its not standard windows palette! To show the correct colors on finished bitmap, it needs to have the user-definied Palette! Ive got a Sourcecode from a guy who uses Delphi - i cant post the Source, due some Copyright. He creates a new ColorPalette (269 Colors) in memory.
 
Back
Top