Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] SKBitmap.Decode(stream) will dispose this stream, feature or bug? #2263

Open
xtuzy opened this issue Sep 28, 2022 · 6 comments
Open

Comments

@xtuzy
Copy link

xtuzy commented Sep 28, 2022

I use SKBitmap.Decode(stream) to create a Bitmap, when i need continue use this stream, i found it is dispose.

sharex-20220928152228

sharex-20220928152307

Skiasharp Version: 2.88.2

@LukePulverenti
Copy link

Are you saying this was different in earlier versions?

@xtuzy
Copy link
Author

xtuzy commented Sep 28, 2022

no difference compare with 2.88.0, i just feel it is not right, stream should be disposed by user like this

using(var stream = ***)
{
  var bitmap = SKBitmap.Decode(stream);
}

@dallonxu
Copy link

dallonxu commented Nov 4, 2022

@xtuzy

Just use SKData to wrap the stream, the stream will not be closed after SKBitmap.Decode.

using(var stream = ***)
{
    var skData = SKData.Create(stream);
    var bitmap = SKBitmap.Decode(skData);
    //stream will not be closed here
}

@maxenko
Copy link

maxenko commented Aug 21, 2023

This is a really bad design choice if not a bug.

@mattleibow
Copy link
Contributor

I'll need to confirm, but I am pretty sure this is expected. The decode usually reads all the way to the end, and the stream may not always be rewindable. So there was not much point in keeping it open... However, the Stream overloads could maybe get an additional parameter to indicate whether or not to close the stream.

@nifiz
Copy link

nifiz commented Nov 19, 2024

@mattleibow Managing a Stream should be left up to the user, not a completely different function they call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

No branches or pull requests

6 participants