2013-01-06 93 views
5

我需要在我的地铁应用程序中显示动画GIF,但我找不到允许它的任何控件。 (我尝试了Image,MediaElementMediaPlayer from Player Framework)WinRT - 在控件中显示动画GIF

有没有可能以某种方式显示动画GIF?

回答

3

虽然我没有检查它是否有效,并且由于空域问题它可能不适用于您 - 您可以尝试在WebView控件中托管您的gif。这可能比Norbert和Carl提出的更好的解决方案容易得多。

+0

工作:) 首先,我检测到GIF的尺寸,然后将webviews的高度和宽度设置为添加20以避免滚动条。 然后只需将webview的源代码设置为gif并且它可以工作:) – Jesse

+0

考虑切换到WebViewBrush。那应该会给你更好的表现 –

3

我刚刚发布了一个库来播放动画GIF:XamlAnimatedGif。你只需要在标准Image控制设置附加属性:

<Image gif:AnimationBehavior.SourceUri="/Images/animated.gif" /> 

(中的xmlns映射xmlns:gif="using:XamlAnimatedGif"

在上WPF中,Windows 8.1和Windows Phone 8.1的作品

0

由于@Filip Skakun说WebView方法的作品。确定它是“黑客”,但所有这些库和解码动作都很慢,动画闪烁(至少在windows phone中)。使用WebView可以让您拥有透明背景的GIF动画。要使用的WebView GIF渲染方法在项目中创建的HTML页面:

<!DOCTYPE html> 
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta charset="utf-8" /> 
    <title>gif rendering</title> 
    <script type="text/javascript"> 
     function SetImageSource(image, source) { 
      document.getElementById(image).src = source; 
     }; 
    </script> 

<style type="text/css"> 
    html, body 
    { 
     -ms-content-zooming:none; 
     -ms-overflow-style: none; 
     -ms-scroll-translation: none; 
     -ms-touch-select: none; 
     overflow: hidden; 
     zoom: 100%; 
    } 
</style> 
</head> 
<body> 
<img id="gifPlaceholder" src=""/> 

<script> 
    SetImageSource("gifPlaceholder", window.top.location.search.substring(1)); 
</script> 
</body> 
</html> 

CSS是很重要的 - 因为它会禁用变焦/滚动/的WebView的触摸移动(这是不可取的在大多数情况下)。添加动画GIF到相同的文件夹(HTML位置)。 XAML代码:

<WebView Name="gifRendererWebView" 
     Source="ms-appx-web:///pathToHtmlInProject.html?gifName.gif" 
     DefaultBackgroundColor="Transparent"/> 

唯一的缺点是,你上WebView占据区域“失去的手势”(你不能使用WebViewBrush,因为你会失去动画)。