【发布时间】:2011-08-26 08:03:39
【问题描述】:
我想在 UI 图像控件中显示 gif 图像。
我有图片 image1;
image1.source = new BitmapImage(new Uri(link, UriKind.Absolute));
但 Uri 中的链接是 .gif 图像。
我读过这个:imagetool 但是我仍然不知道如何使用这个库。我确实下载了库并添加了引用,然后我被卡住了,我想在代码中设置源代码。
你能帮忙解释一下吗?
我的代码目前是这样的:
<UserControl.Resources>
<imagetools:ImageConverter x:Key="ImageConverter" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid HorizontalAlignment="Right" Width="69">
<Border BorderBrush="White" BorderThickness="3" CornerRadius="7" Background="Black">
<Image Width="69" Height="69" Name="canvasImage" Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center" ImageFailed="canvasImage_ImageFailed" />
</Border>
<Border BorderBrush="White" BorderThickness="3" CornerRadius="7" Background="Black">
<imagetools:AnimatedImage Name="canvasGifImage" Width="69" Height="69" Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
</Grid>
</Grid>
In my MainPage.xaml.cs, because I don't know whether it is an png/jpg or a gif, so I have it try to load png/jpg first, if failed then try load gif in the imagetools control name canvasGifImage:
private void DisplayImage(int index, string link)
{
try
{
control1.canvasImage.Source = new BitmapImage(new Uri(link, UriKind.Absolute));
}
catch //if fail to load image as normal, do this
{
//but I dont know how to set Source for the canvasGifImage, help me here:
control1.canvasGifImage.Source = *new BitmapImage(new Uri(link, UriKind.Absolute));*
}
}
【问题讨论】:
-
发布您的代码可以更轻松地查看您在做什么并提供适当的解决方案。
标签: image windows-phone-7 gif