0

我正在使用以下代码来调整和保存图像。请让我摆脱这个错误。我只在我的实时服务器上收到此错误,而它在本地主机上工作。

public void ResizeImage(Int32 height, Int32 width, Stream fromStream, String filename)
{
    var image = System.Drawing.Image.FromStream(fromStream);
    var newWidth = width;
    var newHeight = height;

    var thumbnailBitmap = new Bitmap(newWidth, newHeight);
    var thumbnailGraph = Graphics.FromImage(thumbnailBitmap);
    thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;

    thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;

    var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);

    thumbnailGraph.DrawImage(image, imageRectangle);
    //thumbnailBitmap.Save(toStream, image.RawFormat);
    String path = Server.MapPath("~/signatures/" + filename);
    thumbnailBitmap.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
    thumbnailGraph.Dispose();

    thumbnailBitmap.Dispose();
    image.Dispose();
}
4

1 回答 1

0

你试过谷歌吗?似乎它可能是由一些事情引起的。由于它只在服务器上崩溃,我的第一个猜测是 ASP.NET 在您保存到的文件夹中没有写权限。看这里:

http://weblogs.asp.net/anasghanem/archive/2009/02/28/solving-quot-a-generic-error-occurred-in-gdi-quot-exception.aspx

于 2012-05-03T05:33:19.200 回答