Display GIF in a WP7 application with Silverlight
I would like to display gif in my WP7 application. Is there some way to achieve this ?
I've tryed this one http://imagetools.codeplex.com/ but can't make it working with WP7.
Thanks in advance for any help
Solution 1:
In fact, it's working, but it lacks some documentation.
After some troubles, here's how to use it :
- reference ImageTools
- reference ImageTools.Controls
- reference ImageTools.IO.Gif
Add namespace in xaml :
xmlns:imagetools="clr-namespace:ImageTools.Controls;assembly=ImageTools.Controls"
And resources :
<phone:PhoneApplicationPage.Resources>
<imagetools:ImageConverter x:Key="ImageConverter" />
</phone:PhoneApplicationPage.Resources>
Then use the control with the converter :
<imagetools:AnimatedImage Source="{Binding ImageSource, Converter={StaticResource ImageConverter}}" />
Your ImageSource should be an Uri, for example :
ImageSource = new Uri("http://mysite/my.gif", UriKind.Absolute);
Don't forget to add decoded :
ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
Solution 2:
Check out Jamie Rodriguez's post here on using GIFs with WP7. He uses the ImageTools project from CodePlex.
http://blogs.msdn.com/b/jaimer/archive/2010/11/23/working-with-gif-images-in-windows-phone.aspx
Solution 3:
I struggled to get the accepted answer working. The following solution worked for me to display a static gif.
public ImageResponse(string imageUrl)
{
InitializeComponent();
ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
var imageResponse = new ExtendedImage();
imageResponse.UriSource = new Uri(imageUrl);
imageResponse.LoadingCompleted += this.ImageResponseLoadingCompleted;
}
private void ImageResponseLoadingCompleted(object sender, EventArgs e)
{
var imageResponse = (ExtendedImage)sender;
Classes.Util.UiThread.Invoke(() =>
{
this.ImageResponse.Source = imageResponse.ToBitmap();
});
}
Classes.Util.UiThread is a helper class I use to call the UI Thread
this.ImageResponse is a standard image control
Solution 4:
Is it an animated GIF? If not, I would try converting the GIF to another supported file format before using it in your app.
Solution 5:
WP7 Silverlight supports JPG/PNG.