Show GIF Images in Windows Phone 7.1


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".
Image 1
Image 2
As you can see, after installing it has added a few assemblies in your reference folder.
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;  
  11. // Constructor  
  12.         public MainPage()  
  13.         {  
  14.             InitializeComponent();  
  15.             ImageTools.IO.Decoders.AddDecoder<GifDecoder>();  
  16.             ImageSource = new Uri("", UriKind.Absolute);  
  17.             thisthis.DataContext = this;  
  18.         }  
  19.         public Uri ImageSource { get; set; }   
Finally, run the application to see the result.
Image 4
For more information, download the attached sample application.


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

Similar Articles