A generic error occurred in GDI+, JPEG Image to MemoryStream

前端 未结 30 2020
再見小時候
再見小時候 2020-11-22 06:47

This seems to be a bit of an infamous error all over the web. So much so that I have been unable to find an answer to my problem as my scenario doesn\'t fit. An exception ge

30条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 07:16

    Had a very similar problem and also tried cloning the image which doesn't work. I found that the best solution was to create a new Bitmap object from the image that was loaded from the memory stream. That way the stream can be disposed of e.g.

    using (var m = new MemoryStream())
    {
        var img = new Bitmap(Image.FromStream(m));
        return img;
    }
    

    Hope this helps.

提交回复
热议问题