justinstenning / Direct3DHook

DirectX Capture and Overlays by using Direct3D API hooks
http://spazzarama.com/2011/03/14/c-screen-capture-and-overlays-for-direct3d-9-10-and-11-using-api-hooks
MIT License
580 stars 178 forks source link

Closed stream access exception while saving bitmap (BitmapExtension.ToBitmap) to disk #19

Closed vsoldatkin closed 8 years ago

vsoldatkin commented 9 years ago

A code like

var Bitmap = Screenshot.CapturedBitmap.ToBitmap();
Bitmap.Save(PathToFile);

fails with the "Cannot access closed stream" exception.

Extension method BitmapExtension.ToBitmap is flawed. MSDN states that one must keep the stream open for the lifetime of the Image. It somehow works with the panel in the example application you provided, but saving bitmap ultimately fails.

justinstenning commented 9 years ago

Thanks, I have tweaked the implementation since then, but I will make sure that this behaves correctly.