Hi nauna,
I have created sample. Please refer the below code.
Code
protected void Page_Load(object sender, EventArgs e)
{
System.Drawing.Image normalImage = System.Drawing.Image.FromFile(Server.MapPath("~/Chrysanthemum.jpg"));
System.Drawing.Image grayImage = (System.Drawing.Image)ConvertToGrayscale(new System.Drawing.Bitmap(normalImage));
grayImage.Save(System.IO.Path.Combine(Server.MapPath("~/")) + "Chrysanthemum1.jpg");
}
public static System.Drawing.Bitmap ConvertToGrayscale(System.Drawing.Bitmap original)
{
System.Drawing.Bitmap newBitmap = new System.Drawing.Bitmap(original.Width, original.Height);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBitmap);
System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.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}
});
System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();
attributes.SetColorMatrix(colorMatrix);
g.DrawImage(original, new System.Drawing.Rectangle(0, 0, original.Width, original.Height), 0, 0, original.Width, original.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
g.Dispose();
return newBitmap;
}
Screenshot
Input Output