Repository navigation
Description
Current behavior
On WebAssembly, an animated GIF or animated WebP shows only its first frame when it is set from a stream (BitmapImage.SetSource / SetSourceAsync), or when it comes from a URL whose path doesn't end in .gif or .webp (an endpoint such as /api/avatar/42). The same images animate on Skia desktop, and on WebAssembly when they come from a URL that ends in the extension.
On WebAssembly, ImageSourceHelpers.ReadFromStreamAsCompositionSurface decodes with createImageBitmap, which returns only the first frame. It skips that decode only when a decode size is set or the URI path ends in .gif/.webp, and a stream has no path. The codec path keeps every frame.
On servicing/6.8 the code is the same, and it affects the Skia renderer on WebAssembly.
Expected behavior
An animated GIF or WebP animates on WebAssembly the way it does on desktop, wherever its bytes come from. Animation is a property of the content, and ReadFromStreamAsCompositionSurface already holds the whole encoded file before it picks a decoder, so the header can tell it: GIF87a/GIF89a, or a RIFF....WEBP file whose first chunk is VP8X with the animation flag set.
How to reproduce it (as minimally and precisely as possible)
Add an animated GIF to an app as Assets/animated.gif (the SamplesApp has one at src/SamplesApp/SamplesApp.Samples/Assets/Formats/animated.gif), then:
<StackPanel>
<Image x:Name="fromStream" Width="150" Height="150" />
<Image x:Name="fromExtensionlessUrl" Width="150" Height="150" />
<Image Width="150" Height="150" Source="ms-appx:///Assets/animated.gif" />
</StackPanel>var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/animated.gif"));
using (var stream = await file.OpenReadAsync())
{
var bitmap = new BitmapImage();
await bitmap.SetSourceAsync(stream);
fromStream.Source = bitmap;
}
// Any http(s) URL that returns a GIF and whose path has no extension.
fromExtensionlessUrl.Source = new BitmapImage(new Uri("https://example.com/api/avatar/42"));On net10.0-desktop all three images animate. On net10.0-browserwasm only the third one does, and the first two stay on their first frame. An animated WebP behaves the same way.
Workaround
- Set
DecodePixelWidthorDecodePixelHeighton theBitmapImage. With a decode size set, the image skips the browser decode and goes through the codec, which keeps the frames. - For a URL, make its path end in
.gifor.webp.
Affected platforms
WebAssembly
Uno.Sdk version (and other relevant versions)
master at 52dccee (SkiaSharp 4.151.1), and servicing/6.8 (Skia renderer).
IDE version
Not IDE-specific.
Anything else we need to know?
APNG doesn't animate on any path: Skia's PNG codec decodes only the default image, so it is outside this issue.
Activity