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

前端 未结 30 1405
再見小時候
再見小時候 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 07:00

    if your code is as follows then also this error occurs

    private Image GetImage(byte[] byteArray)
    {
       using (var stream = new MemoryStream(byteArray))
       {
           return Image.FromStream(stream);
        }
    }
    

    The correct one is

    private Image GetImage(byte[] byteArray)
    {
       var stream = new MemoryStream(byteArray))
       return Image.FromStream(stream);        
    }
    

    This may be because we are returning from the using block

提交回复
热议问题