好吧,我很抱歉,这可能是一个菜鸟问题,但我有点卡住了。
所以我正在做的(在我的 asp.net 应用程序上)是从文件系统加载图像:
System.Drawing.Image tempImage;
tempImage = System.Drawing.Image.FromFile(HttpContext.Server.MapPath(originalPath));
然后我做了一些调整大小:
tempImage = my awesomeResizingFunction(tempImage, newSize);
并打算使用以下命令将其保存到文件系统的另一个位置:
string newPath = "/myAwesomePath/newImageName.jpg";
tempImage.Save(newPath);
我得到的是这个错误:
"A generic error occurred in GDI+."
我知道图像是“ok”,因为我可以将其写入浏览器并查看调整后的图像,只有当我尝试保存它时才会收到错误。我有点新,被困住了,我这样做完全错了吗? (嗯,我想这很明显,但你知道我的意思......)
试试这个代码...我使用了相同的代码来调整图像大小并保存。
System.Drawing.Bitmap bmpOut = new System.Drawing.Bitmap(NewWidth, NewHeight);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpOut);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.FillRectangle(System.Drawing.Brushes.White, 0, 0, NewWidth, NewHeight);
g.DrawImage(new System.Drawing.Bitmap(fupProduct.PostedFile.InputStream), 0, 0, NewWidth, NewHeight);
MemoryStream stream = new MemoryStream();
switch (fupProduct.FileName.Substring(fupProduct.FileName.IndexOf('.') + 1).ToLower())
{
case "jpg":
bmpOut.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case "jpeg":
bmpOut.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case "tiff":
bmpOut.Save(stream, System.Drawing.Imaging.ImageFormat.Tiff);
break;
case "png":
bmpOut.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
break;
case "gif":
bmpOut.Save(stream, System.Drawing.Imaging.ImageFormat.Gif);
break;
}
String saveImagePath = Server.MapPath("../") + "Images/Thumbnail/" + fupProduct.FileName.Substring(fupProduct.FileName.IndexOf('.'));
bmpOut.Save(saveImagePath);
where fupProduct
是文件上传控件ID
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)