0

I am getting this error

System.ArgumentException: Parameter is not valid. at System.Drawing.Bitmap..ctor(String filename) at PressRoom.ImageHandler.getResizedImage(String path, Int32 width, Int32 height)

At line

byte[] getResizedImage(String path, int width, int height)
{
        if (path!=null)
        {
            Bitmap imgIn = new Bitmap(path); // exception is thrown
            double y = imgIn.Height;
            double x = imgIn.Width;
}

How do I handle this exception?

1 Answers1

0

Why don't you surround your code with try-catch? The exception is usually thrown when the path is not valid, check twice that file exists or the path is in correct format

Bitmap imgIn;
try
{
    imgIn = new Bitmap(path);
    double y = imgIn.Height;
    double x = imgIn.Width;
}
catch (ArgumentException e)
{
    Console.WriteLine(e.Message);
    return null;
}
rum
  • 222
  • 1
  • 12
  • OP already has the error msg. Your answer doesn't contribute anything towards answering why OP is getting the error. – Steve Jun 19 '18 at 19:43
  • 1
    @Steve, well the question was "how do I handle the exception", so that's how – rum Jun 19 '18 at 19:45