在MemoryStream中调整图像大小时

在MemoryStream中调整图像大小时

本文介绍了在MemoryStream中调整图像大小时,GDI +中发生一般错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ImageProcessor 处理我网站中的图像.

I am using ImageProcessor to process images in my website.

我有此调整大小功能:

 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()时,我得到了一个例外:

I get an exception when it reached the Save function ytSmallThumb.Save():

A generic error occurred in GDI+

从ResizeThumbnailToSmall函数正确返回了图像,并且Stream具有正确大小的图像信息.

The image is returned correctly from ResizeThumbnailToSmall function and the Stream has information of the image with the right size.

推荐答案

ImageProcessor今天让我发疯,每次我调整PNG文件大小时,它都会引发"GDI +中发生一般错误"异常.在回收应用程序池之后,我不再看到该异常.

ImageProcessor makes me crazy today, it throws "A generic error occurred in GDI+" exception everytime I resize PNG files. and after Recycle the application pool I don't see the exception anymore.

希望有帮助.

这篇关于在MemoryStream中调整图像大小时,GDI +中发生一般错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 04:48