Click to See Complete Forum and Search --> : The logic behind converting image to another color table with unsafe.


TomHL
October 24th, 2005, 07:41 AM
Hello all,

I need to do an application that takes a Bitmap object and convert it to one of the color tables below:

1. 16 colors.
2. 256 colors.
3. 24bpp.

I read about lockbits and unsafe code, but how can I change the actual value of the pixels according to the pallets? how do I set their values? there is a formula for red, blue and green?

I just need the theory/idea. then I will convert it myself.

thx.

darwen
October 24th, 2005, 10:28 AM
As I've said before there is no formula for 16 colours or 256 colours. You have to build up a colour table with the colours you require and store the indexes to these colours in the bitmap data.

This is non-trivial : and yet again as I've said before I'd go out there and look up palettised bitmaps using Google.

This is the sort of thing that people write books about !

24bpp is pretty easy though : in the code I gave you before


byte *pbData = // whatever;
pbData[0] = <red value>;
pbData[1] = <green value>;
pbData[2] = <blue value>;


On some systems the red and blue might be swapped.

Darwen.

TomHL
October 24th, 2005, 04:28 PM
1. how do I bulid a colour table?
2. how do I set the ew table on the image (just the syntax)?
3. what books? I searched amazon for good books on imageprocessing with c# and didn't find any. (I also googled it, but stil no answer).
do you have a namesof good books for this image processing in c#?

thx.

darwen
October 24th, 2005, 05:29 PM
Have a look at this :

http://www.webreference.com/dev/graphics/palette.html

It describes colour palettes. It's one of hundreds of pages I found by searching for "colour dithering" or "colour palette".

Darwen.