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

前端 未结 30 2035
再見小時候
再見小時候 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 06:59

    Just to throw another possible solution on the pile, I'll mention the case I ran into with this error message. The method Bitmap.Save would throw this exception when saving an bitmap I had transformed and was displaying. I discovered it would not throw the exception if the statement had a breakpoint on it, nor would it if the Bitmap.Save was preceeded by Thread.Sleep(500) so I suppose there is some sort of resource contention going on.

    Simply copying the image to a new Bitmap object was enough to prevent this exception from appearing:

    new Bitmap(oldbitmap).Save(filename);
    

提交回复
热议问题