is it possible to persist the original data used to build a bitmapimage without reencoding?

You can avoid disposing MemoryStream here (disposing of MemoryStream while good practice doesn’t do anything interesting anyway, there are no resources to dispose):

using var ms = new MemoryStream(bytes);

And then be able to access that same memory stream later by accessing bitmapImage.StreamSource. Note that returned stream Position might be not 0, because BitmapImage might have read it already, so don’t forget to reset position to 0 if necessary. Usually it’s bad idea to call MemoryStream.GetBuffer() (ToArray() is preferred), but in this particular case it might be appropriate to avoid unnecessary copy.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top