As we all know, in the UWP app framework, the image control is unable to play the GIF picture, only the static diagram, so the experience is not particularly friendly. I'm in Win8, WP8.1 time to realize the GIF playback function, but recently found that performance and playback effect is not satisfactory, you can see my stick application, now or with my previous write GIF control, some of the picture playback effect is not very correct, or memory consumption is too high, the main reason is because only the GIF per frame to do a simple processing.
var frame = await decoder. Getframeasync (FrameIndex). AsTask (token); var writeablebitmap = new WriteableBitmap ((int) decoder. Orientedpixelwidth, (int) decoder. Orientedpixelheight); Bitmapframe Bframe = await decoder. Getframeasync (FrameIndex). AsTask (token); TimeSpan delay = TimeSpan.Zero; Bitmappropertyset Bitmappropertyset = await bframe. Bitmapproperties.getpropertiesasync (New List<string> ()). AsTask (token); if (bitmappropertyset! = null) {Bitmappropertyset Delaypropertyset = await (bit mappropertyset["/grctlext"]. Value as Bitmappropertiesview). Getpropertiesasync (new list<string> {"/delay",}); if (delaypropertyset! = null) {delay = Timespan.fromseconds (double). Parse (delaypropertyset["/delay"). Value.tostring ())/100.0); }} if (delay. Equals (TimeSpan.Zero)) {delay = Defaultdelay; } var bitmaptransform = new Bitmaptransform (); var Pixeldataprovider = await frame. Getpixeldataasync (Bitmappixelformat.bgra8, decoder. Bitmapalphamode, Bitmaptransform, Exiforientationmode.ignoreexiforientation, colormanagementmode.do Notcolormanage); var pixels = Pixeldataprovider.detachpixeldata (); using (var Bitmapstream = WriteableBitmap.PixelBuffer.AsStream ()) {Bitmapstream . Write (pixels, 0, pixels. Length); }
This code, you can see that the parsing gif each frame does not handle the GIF parameters, only processing the delay attribute, that is, the playback interval of each frame (this play interval has a relatively silent place, if the delay is zero generally need to add 100 milliseconds, to do the interval, Otherwise GIF will play too fast), but no other picture properties to do processing, resulting in some GIF style errors, but this implementation is relatively simple, performance efficiency what will be higher, and can adapt to most of the GIF playback, so before making some trade-offs.
The passage of time, before knowing that Microsoft released the Win2d graphics Acceleration engine, it is particularly interested, see Microsoft with win2d realized GIF playback demo, did some research, will Microsoft's play demo made some improvements, developed the UWP picture frame IMAGELIB.UWP, The project has been posted to GitHub (Https://github.com/chenrensong/ImageLib.UWP), and the latest version is released on NuGet, and you can
Install-package IMAGELIB.UWP
command to install.
IMAGELIB.UWP support Almost all the URI format, draw on the advantages of many picture frames, support extended image parser, this part can be seen in the demo, this article does not introduce the specific implementation principle, the next time I will and everyone in detail, if you encounter problems in use, welcome message.
Implement GIF playback in a UWP app