我收到此错误
System.ArgumentException:参数无效。 在System.Drawing.Bitmap..ctor(字符串文件名) 在PressRoom.ImageHandler.getResizedImage(String path,Int32 width,Int32 height)
在线
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;
}
如何处理此异常?
答案 0 :(得分:0)
为什么不用try-catch包围代码? 通常在路径无效时引发异常,请检查文件是否存在两次或路径格式正确
Bitmap imgIn;
try
{
imgIn = new Bitmap(path);
double y = imgIn.Height;
double x = imgIn.Width;
}
catch (ArgumentException e)
{
Console.WriteLine(e.Message);
return null;
}