Saving Image to MemoryStream- Generic GDI+ Error

此生再无相见时 提交于 2019-12-01 05:39:43

I think your problem actually lies in your BitmapFromSource method.

You're creating a stream, then creating a bitmap from that stream, then throwing the stream away, then trying to save the bitmap to another stream. However, the documentation for the Bitmap class says:

You must keep the stream open for the lifetime of the Bitmap.

By the time you come to save that bitmap, the bitmap is already corrupted because you've thrown the original stream away.

See: http://msdn.microsoft.com/en-us/library/z7ha67kw

To fix this (bearing in mind I've not written the code let alone tested it), create the MemoryStream inside the first for loop in your first block of code, and pass that memory stream to your BitmapFromSource method as a second parameter.

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