【发布时间】:2015-11-02 19:34:05
【问题描述】:
我想保存调整大小后的图像,但出现 GDI+ 错误。代码:
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(path));
float aspectRatio = (float)image.Size.Width / (float)image.Size.Height;
int newHeight = 200;
int newWidth = Convert.ToInt32(aspectRatio * newHeight);
System.Drawing.Bitmap thumbBitmap = new System.Drawing.Bitmap(newWidth, newHeight);
System.Drawing.Graphics thumbGraph = System.Drawing.Graphics.FromImage(thumbBitmap);
thumbGraph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbGraph.DrawImage(image, imageRectangle);
thumbBitmap.Save("~/images/galeria/thumb/" + FileUpload1.FileName);
thumbGraph.Dispose();
thumbBitmap.Dispose();
image.Dispose();
错误是由这一行引起的:
thumbBitmap.Save("~/images/galeria/thumb/" + FileUpload1.FileName);
有什么办法解决这个问题吗?
编辑1:
System.Drawing.dll 中出现“System.Runtime.InteropServices.ExternalException”类型的异常,但未在用户代码中处理
附加信息:GDI+ 中出现一般错误。
【问题讨论】:
-
请给我们完整的错误描述。
-
调试器。断点。使用它们,也许,你能给我们完整的错误吗?
-
确定是有效路径?有写权限吗?
-
路径存在。 EDIT1 中的整个错误。