Click here to Skip to main content
15,888,263 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public static Bitmap MakeGrayscale3(Bitmap original)
 {
    //create a blank bitmap the same size as original
    Bitmap newBitmap = new Bitmap(original.Width, original.Height);
    
    //get a graphics object from the new image
    Graphics g = Graphics.FromImage(newBitmap);
 
   //create the grayscale ColorMatrix
    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}
       });
 
   //create some image attributes
    ImageAttributes attributes = new ImageAttributes();
 
   //set the color matrix attribute
    attributes.SetColorMatrix(colorMatrix);
 
   //draw the original image on the new image
    //using the grayscale color matrix
    g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
       0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
 
   //dispose the Graphics object
    g.Dispose();
    return newBitmap;
 }


Get: Bitmap original
Returns: newBitmap

I did not know how to send a picture and how to get and save the new image to a new file.
Posted

1 solution

Have a look to:
save image at msdn[^]

I hope it helps you
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900