Greyed Image?

G

Guest

You need a separate image with the grey colors and you paint it instead of
the color version when you want.
 
P

Peter Schottland

Here's a simple algorithm for doing greyscale:

static public Bitmap BitmapGrayScaleWeighted(Bitmap colorBitmap)
{
if (colorBitmap == null)
throw new ArgumentNullException("colorBitmap",
"ImageTools.BitmapGrayScaleWeighted");

Bitmap grayBitmap = new Bitmap(colorBitmap.Width, colorBitmap.Height);

Color colorPixel;
int newRGB;

for (int y = 0; (y < colorBitmap.Height); y++)
for (int x = 0; (x < colorBitmap.Width); x++)
{
colorPixel = colorBitmap.GetPixel(x, y);
newRGB = (int)((0.212671 * colorPixel.R) + (0.715160 * colorPixel.G) +
(0.072169 * colorPixel.B));
grayBitmap.SetPixel(x, y, Color.FromArgb(newRGB, newRGB, newRGB));
}

return grayBitmap;
}

-peter
 

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