Some time ago I was talking with a friend that needed a special requirement for his application: displaying GIF images downloaded from the web. This image format is not supported by Silverlight nor Windows Phone: if you try to download and display a GIF image inside an Image control you’ll get an exception.
So I searched a little bit on the Internet to find a possible solution and I came out withImageTools, a third party library that contains many converters and tools to convert one image from a format to another on the fly. One of the supported scenario is GIF images conversion (that can be animated, too) for Windows Phone.
Let’s see how to use it: the first thing is to add the library to your project and, as usual, the easiest way to do is with NuGet.
Now you are ready to insert the
AnimatedImage control into your page: you simply have to bind the
Source property with a
Uri object (which contains the URL of the gif image) and apply the
And here, instead, is how the ImageSource property is defined in the code:
ImageSource = new Uri("http://www.nonstopgifs.com/animated-gifs/games/games-animated-gif-002.gif", UriKind.Absolute);
We’re almost done: the trick to make the “magic” working is to use one of the decoders that are available in the ImageTools library: these decoders take care of the conversion process and they should be initialized when the application or the page is created, specifying which is the image format to use. We are using this library for GIF conversion, so here is how to register the GIF decoder.
As I anticipated in the beginning of this post, this control supports animated GIFs too: if you try the example GIF used in this post you can see it by yourself.