How to display a GIF picture in Windows Phone

Source: Internet
Author: User
Tags image converter silverlight

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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.