Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 it's impossible - how do i define my own palette to use it?

 

THX !!!!

  • *Experts*
Posted

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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

As far as I know, you can't load that PAL into any .NET datastructure directly (though I've 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 can't find anything else.

 

-Ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
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.
Posted

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];

 

 

That's 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:

  • *Experts*
Posted

You can't 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 you'll have a palette.

 

Two other notes.

 

1. I'm not sure why you need 269 ColorPalette objects. You only need one for the code you have. You're not defining the number of colors in the palette - that's built into the ColorPalette object itself. You're actually defining 269 objects.

 

2. It's perfectly fine to assign a variable NewPalette (or NewPalette[0] like you are) to TMPbmp.Palette. But it's just another reference to the same object (a ColorPalette is a class, not a struct). You get code readability only. You don't need to use:

TMPbmp.Palette = NewPalette[0]

to get the palette updated. You're always referencing the same palette whether you use TMPbmp.Palette.Entries... or NewPalette[0].Entries...

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Ok, that's 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?

  • *Experts*
Posted

You can't 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 Palette's color 1, not the actual color of 1 (which would be almost black).

 

If you want a 16bpp bitmap that's fine, but you don't need a Palette. You can set each pixel's 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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
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? That's a little bit stupid - or isn't it? I mean, if i load a picture in PSP 7 it knows the Color by the Palette! I still can't convert each byte from a file into a color! Because the format of file and the format of palette doesn't match! So i had to Read a Byte, check which value and set Color - i mean, that's impossible - isn't there another way? Have you an exmpl. or an idea? Please post!
  • *Experts*
Posted

Maybe you can explain what it is you're 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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
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! It's not standard windows palette! To show the correct colors on finished bitmap, it needs to have the user-definied Palette! I've got a Sourcecode from a guy who uses Delphi - i can't post the Source, due some Copyright. He creates a new ColorPalette (269 Colors) in memory.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...