这是我现在得到的错误
System.Runtime.InteropServices.ExternalException(0x80004005):GDI +中发生一般错误。在System.Drawing.Image.Save(String filename,ImageCodecInfo encoder,EncoderParameters encoderParams)
我在同一台机器的其他网站上使用相同的代码并且没有问题我真的不知道发生了什么请给我解决方案
这是我的代码
double newHeight = 0;
double newWidth = 0;
double scale = 0;
//create new image object
Bitmap curImage = new Bitmap(filePath);
//Determine image scaling
if (curImage.Height > curImage.Width)
{
scale = Convert.ToSingle(size) / curImage.Height;
}
else
{
scale = Convert.ToSingle(size) / curImage.Width;
}
if (scale < 0 || scale > 1) { scale = 1; }
//New image dimension
newHeight = Math.Floor(Convert.ToSingle(curImage.Height) * scale);
newWidth = Math.Floor(Convert.ToSingle(curImage.Width) * scale);
//Create new object image
Bitmap newImage = new Bitmap(curImage, Convert.ToInt32(newWidth), Convert.ToInt32(newHeight));
Graphics imgDest = Graphics.FromImage(newImage);
imgDest.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
imgDest.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
imgDest.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
imgDest.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
ImageCodecInfo[] info = ImageCodecInfo.GetImageEncoders();
EncoderParameters param = new EncoderParameters(1);
param.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
//Draw the object image
imgDest.DrawImage(curImage, 0, 0, newImage.Width, newImage.Height);
//Save image file
newImage.Save(saveFilePath, info[1], param);
//Dispose the image objects
curImage.Dispose();
newImage.Dispose();
imgDest.Dispose();
}
答案 0 :(得分:2)
如果您运行的帐户无法保存到此行saveFilePath
处的路径,则会收到GDI错误消息:
newImage.Save(saveFilePath, info[1], param);