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

前端 未结 30 2017
再見小時候
再見小時候 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:07

    I encountered the problem too. The problem was due to the loading stream being disposed. But I did not dispose it, it was inside .Net framework. All I had to do was use:

    image_instance = Image.FromFile(file_name);
    

    instead of

    image_instance.Load(file_name);
    

    image_instance is of type System.Windows.Forms.PictureBox! PictureBox's Load() disposes the stream which the image was loaded from, and I did not know that.

提交回复
热议问题