Say a few days ago a friend of mine talked to me about a particular need to download a GIF picture from the Web and then display it on Windows Phone. We all know that both Silverlight and Windows Phone do not support GIF image format. If you try to download a GIF image and then display it on the image control, you will get an exception.
So I found the Imagetools library on the web, which is a third-party library with a variety of image format converters that support image conversion for GIF format.
How to use:
First add this library reference to your project, as shown below, we use NuGet to get the Imagetools
In order to achieve our goal, there are two parts required:
1,animatedimage, it replaces the standard Silverlight ImageControl.
2,imageconverter, complete the conversion of the picture format.
Both objects are under the Imagetools.controls namespace, so you should also declare namespaces in XAML
<phone:PhoneApplicationPage.Resources>
<imagetools:imageconverter x:key= "ImageConverter"/>
</phone:PhoneApplicationPage.Resources>
Once you've introduced the namespace, you can add converter as a page resource, as shown in the following code
Code
Of course, if you want this converter to work throughout the project, you can add this element to the Application.Resources node of the App.xaml file.
OK, now you can add the Animatedimage control to the page, where you can bind the control's Source property to a Uri object, and then set a reference to the Image Converter. As follows:
<StackPanel>
<imagetools:animatedimage x:name= "Image" source= "{Binding Path=imagesource, converter={ StaticResource ImageConverter} "/>
</StackPanel>
The ImageSource property is then set in the background C # code as follows.
ImageSource = new Uri ("Http://www.nonstopgifs.com/animated-gifs/games/games-animated-gif-002.gif", Urikind.absolute);
Finally, we add such a line of code to the page's construction method to support the function of GIF decoding.
Public MainPage ()
{
InitializeComponent ();
Imagetools.io.decoders.adddecoder<gifdecoder> ();
}
Well, compile it again and run, and you'll definitely see the animated GIF picture
Original Connection Address: http://wp.qmatteoq.com/how-to-display-gif-images-in-a-windows-phone-application/