C# GDI+;中发生一般性错误;实时服务器上出现错误。但并非所有图像都是如此

C# GDI+;中发生一般性错误;实时服务器上出现错误。但并非所有图像都是如此,c#,asp.net,gdi+,image-uploading,C#,Asp.net,Gdi+,Image Uploading,我的实时服务器上出现“GDI+中发生一般错误”错误。在本地,没有任何错误。关于这一点,我查了很多帖子。人们说这可能是因为写入权限、错误的路径或某些图像格式 但就我而言,没有一个是原因。因为我大部分时间都可以上传。这意味着书面许可是可以的。图像格式正常。等等 但对于某些图像,会出现此错误。我无法调试或获取有关错误的详细信息,因为它只发生在live server上。对于在live server上引发异常的同一映像,可以在localhost上运行 有什么想法吗?这个错误还有其他原因需要我考虑吗 提前谢

我的实时服务器上出现“GDI+中发生一般错误”错误。在本地,没有任何错误。关于这一点,我查了很多帖子。人们说这可能是因为写入权限、错误的路径或某些图像格式

但就我而言,没有一个是原因。因为我大部分时间都可以上传。这意味着书面许可是可以的。图像格式正常。等等

但对于某些图像,会出现此错误。我无法调试或获取有关错误的详细信息,因为它只发生在live server上。对于在live server上引发异常的同一映像,可以在localhost上运行

有什么想法吗?这个错误还有其他原因需要我考虑吗

提前谢谢

保存过程

 private string ResizeAndSaveImage(FileUpload file, int maxWidth, int maxHeight, string rootPath)
{
    string ext = System.IO.Path.GetExtension(file.FileName).TrimStart(".".ToCharArray()).ToLower();
    Bitmap uploadedImage = new Bitmap(file.FileContent);
    Bitmap resizedImage = Utility.GetResizedImage(uploadedImage, maxWidth, maxHeight);

    //Save the image
    string urlName = System.Guid.NewGuid().ToString() + "." + ext;
    string virtualPath = rootPath + urlName;
    string tempFileName = Server.MapPath(virtualPath);
    resizedImage.Save(tempFileName, uploadedImage.RawFormat);
    return urlName;
}
调整大小方法

public static Bitmap GetResizedImage(Bitmap source, int width, int height)
{
    //This function creates the thumbnail image.
    //The logic is to create a blank image and to
    // draw the source image onto it

    Bitmap thumb = new Bitmap(width, height);
    Graphics gr = Graphics.FromImage(thumb);

    gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
    gr.SmoothingMode = SmoothingMode.HighQuality;
    gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
    gr.CompositingQuality = CompositingQuality.HighQuality;

    gr.DrawImage(source, 0, 0, width, height);
    return thumb;
}
活动详情

<Data>ExternalException</Data>
<Data>A generic error occurred in GDI+. at
    System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
    EncoderParameters encoderParams) at
    OasisEstateUI.AdminPages.ApartmentManagement.ResizeAndSaveImage(FileUpload
    file, Int32 maxWidth, Int32 maxHeight, String rootPath) at
    OasisEstateUI.AdminPages.ApartmentManagement.btnSaveApartmentImage_Click(Object
    sender, EventArgs e) at
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    eventArgument) at System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean
    includeStagesAfterAsyncPoint)</Data>
ExternalException
GDI+中发生一般性错误。在
System.Drawing.Image.Save(字符串文件名、ImageCodeInfo编码器、,
EncoderParameters encoderParams)位于
OasieStateUI.AdminPages.ApartmentManagement.ResizeAndSaveImage(文件上载
文件,Int32 maxWidth,Int32 maxHeight,字符串根路径)
OAISeStateUI.AdminPages.ApartmentManagement.btnSaveApartmentImage\u单击(对象
发件人,事件参数(e)位于
System.Web.UI.WebControl.Button.RaisePostBackEvent(字符串
System.Web.UI.Page.ProcessRequestMain中的eventArgument(布尔值)
includeStagesBeforeAsyncPoint,布尔值
includeStagesAfterAsyncPoint)

您是否上载图像并将其转换为其他内容?若你们只是保存一个从客户端收到的图像,那个么GDI+就不应该参与进来……在上传之前,我有一些调整大小的过程。我已经编辑了我的帖子。这只是一个猜测,但…你们在服务器上有哪个操作系统版本?图像过滤器(用于导入/导出)在GDI+版本之间略有不同。您的服务器可能不支持您在本地读取的内容。如果您试图同时写入多个映像,您可能会看到此错误。2008 R2在live server上,并且我的本地pc具有win8。如果图像过滤器之间存在一些差异,您不需要为所有jpg格式获取此错误吗?