Display GIF in a WP7 application with Silverlight

2019-01-05 03:08发布

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

6条回答
够拽才男人
2楼-- · 2019-01-05 03:45

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

查看更多
狗以群分
3楼-- · 2019-01-05 03:47

Is it an animated GIF? If not, I would try converting the GIF to another supported file format before using it in your app.

查看更多
聊天终结者
4楼-- · 2019-01-05 03:54

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

查看更多
淡お忘
5楼-- · 2019-01-05 04:02

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>();
查看更多
Animai°情兽
6楼-- · 2019-01-05 04:04

WP7 Silverlight supports JPG/PNG.

查看更多
聊天终结者
7楼-- · 2019-01-05 04:05

As per http://msdn.microsoft.com/en-us/library/ff462087(VS.92).aspx the Silverlight image control does not support GIF files.

By using ImageTools you are converting the GIF file to something else on the fly on the device. If you are using gif files that you have control of (i.e. You are bundling them in the XAP or they are coming from your webserver.) you should use converted versions of these files.

This will mean that the app has to do less.
The knock on effect is that:
1. You will have to write less code.
2. The app will have to do less work and so will perform slightly better.

Of course, this doesn't cover animated GIFs. For these you'll need to use a different approach.

查看更多
登录 后发表回答