Introduction

This article discusses how to load .gif extension images in Windows Phone 7.1. As we all know Windows Phone 7 supports .jpg and .png images, so this article will be very helpful if you want to show .gif images.

Getting Started

Create a Windows Phone Application using the following:
  1. Open Visual Studio 2010.
  2. "File" -> "New" -> "Project..."
  3. Select "Silverlight for Windows Phone" from the Installed templates and choose "Windows Phone Application"
  4. Enter the name and choose the location.
  5. Click "OK".
First of all, right-click on Solutions Explorer and click "Manage NuGet Packages..." and search by name for ImageTools and click "Install".
img1.jpg
Image 1
img2.jpg
Image 2
As you can see, after installing it has added a few assemblies in your reference folder.
image3.jpg
Image 3
Let's work on the UI part now.
First of all the following add namespace of image tools in the .xaml file:
  1. xmlns:imagetools="clr-namespace:ImageTools.Controls;assembly=ImageTools.Controls"
Now add the following image convertor resource.
  1. <phone:PhoneApplicationPage.Resources>
  2. <imagetools:ImageConverter x:Key="ImageConverter" />
  3. </phone:PhoneApplicationPage.Resources>
Now add this:
  1. <!--ContentPanel - place additional content here-->
  2. <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
  3. <imagetools:AnimatedImage Source="{Binding Path=ImageSource, Converter={StaticResource ImageConverter}}" />
  4. </Grid>
Now let's work on the code part.
  1. using Microsoft.Phone.Controls;
  2. using ImageTools.IO.Gif;
  3. using System.Windows.Media.Imaging;
  4. using Microsoft.Xna.Framework.Media;
  5. using System.IO;
  6. using System.Text;
  7. using ImageTools;
  8. using System.Threading;
  9. using System.Windows.Data;
  10. // Constructor
  11. public MainPage()
  12. {
  13. InitializeComponent();
  14. ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
  15. ImageSource = new Uri("http://i1118.photobucket.com/albums/k607/Ashe-kun/9285a6048c8a769fba5d.gif", UriKind.Absolute);
  16. thisthis.DataContext = this;
  17. }
  18. public Uri ImageSource { get; set; }
Finally, run the application to see the result.
img4.jpg
Image 4
For more information, download the attached sample application.

Summary

In this article, we learned about Show GIF Images in Windows Phone 7.1.