[英]System.Runtime.InteropServices.ExternalException: 'A generic error occurred in GDI+.'
[英]System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+
我在asp.net C#应用程序中有一个旋转图像的代码,这是我的代码:
protected void ImgBtn180_Click(object sender, ImageClickEventArgs e)
{
try
{
string vImageName = LblFarmId.Text;
string vPath = "~/attachments/survey/" + vImageName + ".jpg";
Image1.ImageUrl = vPath;
//get the path to the image
string path = Server.MapPath(vPath);
//create an image object from the image in that path
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
//rotate the image
img.RotateFlip(RotateFlipType.Rotate180FlipXY);
//save the image out to the file
img.Save(path);
//release image file
img.Dispose();
Random rnd = new Random();
Image1.ImageUrl = vPath + "?" + rnd;
}
catch (Exception ee)
{
LblCatchError.Text = ee.ToString();
}
}
当我在服务器上运行它时,有时会出现以下错误
System.Runtime.InteropServices.ExternalException:GDI +中发生一般错误。 在System.Drawing.Image.Save(字符串文件名)在System.Drawing.Image.Save(字符串文件名,ImageCodecInfo编码器,EncoderParameters encoderParams)在System.Drawing.Image.Save(字符串文件名,ImageFormat格式)
有时会出现以下错误
System.OutOfMemoryException:内存不足。 在System.Drawing.Image.FromFile(String filename,Boolean useEmbeddedColorManagement)在System.Drawing.Image.FromFile(String filename)
我阅读了有关此错误的所有文章和解决方案,但没有任何效果。 一些人说:“确保所需的文件夹具有读/写权限。” 它具有权限..
有人说:“您必须配置图像对象以释放服务器上的内存。” ,我已经有了代码img.Dispose(); 释放图像文件,
代码可能是什么问题? 有什么建议吗?
我将此(Rotate180FlipXY)更改为(Rotate180FlipNone),之后问题已解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.