Changing the function color covertion (unsafe)

G

Guest

hello,

the code below make a bitmap greyscale.
how do I change the code that the result will be 16 colors/256 colors
instead of greyscale?
somebody can explain the theory behind the calculations?

for (int y = 0; y < size.Y; y++)
{
PixelData* pPixel = PixelAt(0, y);
for (int x = 0; x < size.X; x++)
{
byte value = (byte) ((pPixel->red + pPixel->green + pPixel->blue) / 3);
pPixel->red = value;
pPixel->green = value;
pPixel->blue = value;
pPixel++;
}
}


thx very much.
 
R

Rob Schieber

TomHL said:
hello,

the code below make a bitmap greyscale.
how do I change the code that the result will be 16 colors/256 colors
instead of greyscale?
somebody can explain the theory behind the calculations?

for (int y = 0; y < size.Y; y++)
{
PixelData* pPixel = PixelAt(0, y);
for (int x = 0; x < size.X; x++)
{
byte value = (byte) ((pPixel->red + pPixel->green + pPixel->blue) / 3);
pPixel->red = value;
pPixel->green = value;
pPixel->blue = value;
pPixel++;
}
}


thx very much.

Take a look at this article
http://msdn.microsoft.com/library/d.../usingacolormatrixtotransformasinglecolor.asp
You'll need GDI+ and use a colormatrix. ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top