You'll find this tutorial helpful as it shows three different ways to do what you want. The last is my favorite and does its trick by using a ColorMatrix:
http://www.switchonthecode.com/tutorials/csharp-tutorial-convert-a-color-image-to-grayscale[
^]!
Hope this helps you!
Modification
Code sample: All you need to create is a form with a PictureBox on it!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace GrayImage
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Image normalImage = Image.FromFile(@"D:\Data\Media\Photo\2009\25-12-2009\DSC_0073.jpg");
Image grayScaled = (Image)MakeGrayscale3(new Bitmap(normalImage));
pictureBox1.BackgroundImageLayout = ImageLayout.Zoom;
pictureBox1.BackgroundImage = grayScaled;
}
public static Bitmap MakeGrayscale3(Bitmap original)
{
Bitmap newBitmap = new Bitmap(original.Width, original.Height);
Graphics g = Graphics.FromImage(newBitmap);
ColorMatrix colorMatrix = new ColorMatrix(
new float[][]
{
new float[] {.3f, .3f, .3f, 0, 0},
new float[] {.59f, .59f, .59f, 0, 0},
new float[] {.11f, .11f, .11f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
});
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(colorMatrix);
g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
g.Dispose();
return newBitmap;
}
}
}
Best Regards,
Manfred