我正在使用ImageProcessor处理我网站中的图像。
我有这个调整大小的功能:
public Image ResizePhoto6version(Image img, int width, int height)
{
using (var ms = new MemoryStream())
{
using (var imgf = new ImageFactory(false))
{
imgf.Load(img)
.Resize(new ResizeLayer(new Size(width, height), ResizeMode.Max))
.Save(ms);
return Bitmap.FromStream(ms);
}
}
}
在网络服务中,我运行以下代码:
MemoryStream ytSmallStream = new MemoryStream();
MemoryStream ytMediumStream = new MemoryStream();
System.Drawing.Image ytSmallThumb = null;
System.Drawing.Image ytMediumThumb = null;
ytSmallThumb.Save(ytSmallStream, ImageFormat.Jpeg);
ytSmallStream.Position = 0;
ytMediumThumb.Save(ytMediumStream, ImageFormat.Jpeg);
ytMediumStream.Position = 0;
当它到达保存函数 ytSmallThumb.Save() 时出现异常:
A generic error occurred in GDI+
图像从 ResizeThumbnailToSmall 函数正确返回,并且 Stream 具有正确大小的图像信息。