Why does SkiaSharp fail to load some image in UWP when calling SKBitmap.Decode?

Viewed 691

This is totally strange.

I am trying to load images in UWP with StorageFile using the following code:

using (var stream = await storageFile.OpenStreamForReadAsync())
{
    SKBitmap bitmap = SKBitmap.Decode(stream);
    // the rest
}

However, some pictures fail at the line of calling SKBitmap.Decode, with this error message:

Value cannot be null.
Parameter name: buffer

I check the stream in debugger, it is not null and it has value. I even put this later:

                        if (stream.CanRead && stream.CanSeek)
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                        }

Those files always fail. For example, one is this:

enter image description here

I am not sure if anyone else can reproduce it with this image I upload to SO. Also, I have opened all restriction, so it's not about permission. This photo can be displayed get calling GetThumbnailAsync, so the app setting is fine.


Now it is the strangest thing. If I do this:

                        SKImage img = SKImage.FromEncodedData(stream);
                        SKBitmap bitmap = SKBitmap.FromImage(img);

It works for those photos!

This drives me crazy!

I mean, I found a way to make it work, but why?

0 Answers
Related