Image processing

Image processing

I am following this link:

http://www.switchonthecode.com/tutorials/csharp-tutorial-convert-a-color-image-to-grayscale

public static Bitmap MakeGrayscale(Bitmap original)
{
   //make an empty bitmap the same size as original
   Bitmap newBitmap = new Bitmap(original.Width, original.Height);

   for (int i = 0; i < original.Width; i++)
   {
      for (int j = 0; j < original.Height; j++)
      {
         //get the pixel from the original image
         Color originalColor = original.GetPixel(i, j);

         //create the grayscale version of the pixel
         int grayScale = (int)((originalColor.R * .3) + (originalColor.G * .59)
             + (originalColor.B * .11));

         //create the color object
         Color newColor =  Color.FromArgb(grayScale, grayScale, grayScale);
         
         //set the new image's pixel to the grayscale version
         newBitmap.SetPixel(i, j, newColor);
        }
    }

    return newBitmap;
}

I AM PASSING VALUES TO THIS METHOD AS:

    protected void grayscale_Click(object sender, EventArgs e)
    {
        //Get the path of image file

        string path = Image1.ImageUrl;



        //create bitmap from path and pass as argument to function makegryscale2

        Bitmap b = MakeGrayscale(new Bitmap(path.Substring(2)));



        //overwrite with saving at same path

        b.Save(path);


        //set it imageurl

        Image1.ImageUrl = path;

 
    }

BUT it is giving me an error, the error says Invalid Parameter. plz let me know how can i use this method????

The Reddest
08/18/2010 - 10:00

Where does it say the parameter is invalid. Does the debugger point to a line of code?

reply

Add Comment

Put code snippets inside language tags:
[language] [/language]

Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]

See here for supported languages.

Javascript must be enabled to submit anonymous comments - or you can login.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.