Bitmap.DecodeToWidth() fails in 0.10.11, 0.10.12 and 0.10.13
See original GitHub issueDescribe the bug
Fails to load bitmap in 0.10.11, 0.10.12 and 0.10.13. Succeeds in 0.10.10 and earlier.
System.ArgumentNullException: Value cannot be null. (Parameter 'buffer')
at SkiaSharp.SKManagedStream.OnReadManagedStream(IntPtr buffer, IntPtr size)
at SkiaSharp.SKManagedStream.OnRead(IntPtr buffer, IntPtr size)
at SkiaSharp.SKAbstractManagedStream.ReadInternal(IntPtr s, Void* context, Void* buffer, IntPtr size)
at SkiaSharp.SkiaApi.sk_codec_get_pixels(IntPtr codec, SKImageInfoNative* info, Void* pixels, IntPtr rowBytes, SKCodecOptionsInternal* options)
at SkiaSharp.SKCodec.GetPixels(SKImageInfo info, IntPtr pixels, Int32 rowBytes, SKCodecOptions options)
at SkiaSharp.SKCodec.GetPixels(SKImageInfo info, IntPtr pixels)
at SkiaSharp.SKBitmap.Decode(SKCodec codec, SKImageInfo bitmapInfo)
at Avalonia.Skia.ImmutableBitmap..ctor(Stream stream, Int32 decodeSize, Boolean horizontal, BitmapInterpolationMode interpolationMode) in /_/src/Skia/Avalonia.Skia/ImmutableBitmap.cs:line 69
at Avalonia.Skia.PlatformRenderInterface.LoadBitmapToWidth(Stream stream, Int32 width, BitmapInterpolationMode interpolationMode) in /_/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs:line 124
at Avalonia.Media.Imaging.Bitmap.DecodeToWidth(Stream stream, Int32 width, BitmapInterpolationMode interpolationMode) in /_/src/Avalonia.Visuals/Media/Imaging/Bitmap.cs:line 24
I believe it is due to using SkiaSharp 2.88.0-preview.178 since 0.10.11: https://github.com/mono/SkiaSharp/issues/1752 https://github.com/mono/SkiaSharp/issues/1551
To Reproduce
using (var memoryStream = new MemoryStream(path)) {
var bitmap = Bitmap.DecodeToWidth(memoryStream, 80);
}
Desktop (please complete the following information):
- OS: Windows 10
- Version 0.10.13
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Probably fixed by: https://github.com/mono/SkiaSharp/pull/2045
Would it be possible to implement the workaround suggested by @AndersMad in https://github.com/mono/SkiaSharp/issues/1551#issuecomment-756685252? Because that seems to solve the issue, and it doesn’t look like SkiaSharp will fix the underlying bug anytime soon. I didn’t create a PR because I don’t know what (performance) implications this change might have.
Example: https://github.com/Fusion86/Avalonia/commit/fa970142922e9a08c7aa26ce5446deabeab657cb