[BUG] SkBitmap.Decode always fail some images, but using SKImage.FromEncodedData works
See original GitHub issueDescription
I am trying to load images in UWP with StorageFile, but some images always fail with a weird error message.
Code
using (var stream = await storageFile.OpenStreamForReadAsync())
{
SKBitmap bitmap = SKBitmap.Decode(stream);
// the rest
}
Expected Behavior
the image should be loaded
Actual Behavior
some pictures fail at the line of calling SKBitmap.Decode, with this error message:
Value cannot be null.
Parameter name: buffer
Basic Information
- Version with issue: 2.80.3-preview.24
- Last known good version: N/A
- IDE: VS.NET
- Platform Target Frameworks: 10.0.19041.0 - 10.0.17763.0
- Android:
- iOS:
- Linux:
- macOS:
- Tizen:
- tvOS:
- UWP: 6.2.10
- watchOS:
- Windows Classic:
- Target Devices: x64
** Details **
The manifest permission is all opened. For those images that fail, I can call GetThumbnailAsync properly.
Moreover, the stream is not null, I added the following code:
if (stream.CanRead && stream.CanSeek)
{
stream.Seek(0, SeekOrigin.Begin);
}
these lines pass, and the Decode still failed.
However, if I do this instead:
SKImage img = SKImage.FromEncodedData(stream);
SKBitmap bitmap = SKBitmap.FromImage(img);
Now those images can be loaded.
but why?
Screenshots
I uploaded one failed image in SO: https://stackoverflow.com/questions/66096184/why-does-skiasharp-fail-to-load-some-image-in-uwp-when-calling-skbitmap-decode
Reproduction Link
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:9 (3 by maintainers)
Top Related StackOverflow Question
Can it do anything with “some images” are thoses with specific metadata, causing this to happen?..
I have the following error happening with stable 2.80.3 on iOS 14.x (on iOS 12.x it’s not happening):
var bitmap = SKBitmap.Decode(stream);crash boom bang:
Downgrading to 2.80.2 solved it…
SKBitmap bitMap = SKBitmap.FromImage(SKImage.FromEncodedData(new MemoryStream(mediaFileBytearray)));
Does not work using SKImage too
skia version 2.80.3