Display an Animated GIF in a Metro App

2019-01-15 20:32发布

Is there a control to show an animated gif in a Windows Store (Metro) app in Windows 8? I am using C# and XAML with databinding.

6条回答
欢心
2楼-- · 2019-01-15 20:51

This is probably overkill, but you could try using a WebView to display the GIF. The WebView control introduces its own set of headaches, however, so unless you're willing to deal with said headaches, I would recommend avoiding it unless you absolutely have to use it.

查看更多
够拽才男人
3楼-- · 2019-01-15 20:54

I managed to display gif's in my windows 8 metro app simply by converting the gifs to jpegs and then running an infinite loop.

The code is as follows :

public async void UpdateImage() {

        await Task.Delay(300);

        var frame = this.Frame.CurrentSourcePageType.Name;

        if (frame != ("CURRENTFRAME")) return;
        if (count <= 4)
        {
            var img = (BitmapImage) Resources["bitmap" + count];
            imgTap.Source = img;
            UpdateLayout();
            count++;
            UpdateImage();
        }
        else
        {
            count = 1;
            UpdateImage();
        }
    }

So basically I'm saving the converted jpegs in my page.resources and then naming them as bitmap1,bitmap2 .. etc . I m checking whether the current frame is the frame which has to display the gif or else the gif code would run in the background for the entire time which is a waste of memory and CPU. Just call this method on any of the Loaded method and it should run fine.

查看更多
We Are One
4楼-- · 2019-01-15 20:56

The Image control doesn't support animated GIFs. You will need to extract the frames and animate them on your own timer.

You should take a look at this link which might help you regarding your question:

http://advertboy.wordpress.com/2012/05/08/animated-gifs-in-xamlc/

查看更多
做自己的国王
5楼-- · 2019-01-15 20:56

If I am right then Silverlight doesn't support GIF and Metro Apps are based on Silverlight platform. Hence dont contain support for GIF images natively. You can however use 3rd party controls like http://www.componentone.com/SuperProducts/ImageSilverlight/.

查看更多
霸刀☆藐视天下
6楼-- · 2019-01-15 21:07

You cannot display an animated gif in a grid. However, you can display an animated gift in the webview controller.

查看更多
ゆ 、 Hurt°
7楼-- · 2019-01-15 21:14

Just for a note: you can use the BitmapDecoder class to read the GIF frames, create a storyboard an animated them.

I've got an example of an Windows 8 user control on my blog: http://www.henrikbrinch.dk/Blog/2013/02/21/Windows-8---GIF-animations--the-RIGHT-way

查看更多
登录 后发表回答