我需要在我的地铁应用程序中显示动画GIF,但我找不到允许它的任何控件。 (我尝试了Image
,MediaElement
和MediaPlayer
from Player Framework)WinRT - 在控件中显示动画GIF
有没有可能以某种方式显示动画GIF?
我需要在我的地铁应用程序中显示动画GIF,但我找不到允许它的任何控件。 (我尝试了Image
,MediaElement
和MediaPlayer
from Player Framework)WinRT - 在控件中显示动画GIF
有没有可能以某种方式显示动画GIF?
虽然我没有检查它是否有效,并且由于空域问题它可能不适用于您 - 您可以尝试在WebView控件中托管您的gif。这可能比Norbert和Carl提出的更好的解决方案容易得多。
这不能本身做到,但你可以检查出
http://imagetools.codeplex.com/
它做所有你想要的。 你也可以检查此
http://blogs.msdn.com/b/jstegman/archive/2009/09/08/silverlight-3-sample-updates.aspx
其中包含一个GIF解码库
在这里你有一个很好的教程如何插入GIF到Metro风格应用程序:
http://advertboy.wordpress.com/2012/05/08/animated-gifs-in-xamlc/
但最简单的方法就是使用这个项目:
您可以通过在.NET Framework中使用BitmapDecoder类来实现本地化。我在我的博客上有一个示例,演示如何实现能够从资源gif文件中显示动画GIF的AnimationControl。退房:http://www.henrikbrinch.dk/Blog/2013/02/21/Windows-8---GIF-animations--the-RIGHT-way
优秀... !!! –
我刚刚发布了一个库来播放动画GIF:XamlAnimatedGif。你只需要在标准Image
控制设置附加属性:
<Image gif:AnimationBehavior.SourceUri="/Images/animated.gif" />
(中的xmlns映射xmlns:gif="using:XamlAnimatedGif"
)
在上WPF中,Windows 8.1和Windows Phone 8.1的作品
由于@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
,因为你会失去动画)。
工作:) 首先,我检测到GIF的尺寸,然后将webviews的高度和宽度设置为添加20以避免滚动条。 然后只需将webview的源代码设置为gif并且它可以工作:) – Jesse
考虑切换到WebViewBrush。那应该会给你更好的表现 –