Pregunta

I have been trying to display an animated gif on my app (c# + xaml). Here its given that gif format is supported by WP8 then why is my gif not visible. Any idea how to make an animated gif run?

¿Fue útil?

Solución

Most apps use the ImageTools library. It's a memory hog, but it works. Alternatively, you can try to embed a WebBrowser control in your app and have it load the animated gif.

The application Baconography is so far the only WP8 application I've heard of that uses a custom GIF renderer. The application is open-source, but I don't know if their license allows you to re-use the code in your own app. https://github.com/Synergex/Baconography

Otros consejos

Another option as if you do not want to add a dependency is to modify the image so that each frame exists sequentially width ways and only show each frame at a time. So in the xaml:

<Canvas Grid.Column="0" Width="32" Height="32">
    <Image x:Name="Image" Source="/Resources/animation.gif">
        <Image.Clip>
            <RectangleGeometry Rect="0 0 32 32"></RectangleGeometry>
        </Image.Clip>
    </Image>
</Canvas>

In C# in a timer only show a particular frame:

image.Clip = new RectangleGeometry {
                                       Rect =
                                           new Rect(
                                               frame * width,
                                               0,
                                               width,
                                               height)
                                           };
Canvas.SetLeft(image, -1 * width * frame)

Where width is the width of each frame, height is the height of the image, and frame is the current position of the animation. The width and height should map the clipping in the xaml.

I just released a new library to display animated GIFs on WPF, Windows 8.1 and Windows Phone 8.1: https://github.com/XamlAnimatedGif/XamlAnimatedGif

Unlike ImageTools, it's very memory efficient because it only decodes the current frame on the fly and discards the previous frame (it's probably a bit more CPU-intensive, though)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top