A generic error occurred in GDI+ when resizing image in MemoryStream

帅比萌擦擦* 提交于 2020-01-16 03:08:13

问题


I am using ImageProcessor to process images in my website.

I have this resize function:

 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);
            }
        }
    }

In the webservice, I run this code:

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;

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

A generic error occurred in GDI+

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

来源:https://stackoverflow.com/questions/51280935/a-generic-error-occurred-in-gdi-when-resizing-image-in-memorystream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!