Display an Animated GIF in a Metro App

試著忘記壹切 提交于 2020-01-05 07:17:13

问题


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.


回答1:


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/




回答2:


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




回答3:


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




回答4:


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.




回答5:


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.




回答6:


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/.



来源:https://stackoverflow.com/questions/13213042/how-to-show-a-gif-image-in-windows-rt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!