在图像 UI 控制 Windows Phone 7 中查看 gif 图像

发布于 2024-12-01 12:51:17 字数 1985 浏览 0 评论 0原文

我想在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));*

        }
    }

I want to display the gif image in the UI image control.

I have Image image1;

image1.source = new BitmapImage(new Uri(link, UriKind.Absolute));

but the link in Uri is a .gif image.

I have read this: imagetool however I still not get it how to use the library. I did download the library and add references, then from that I'm stuck, I want to set source in code.
Can you help explains it a little bit more?

My code currently like this:

<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));*

        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘心安 2024-12-08 12:51:17

替换异步代码中 ManualResetEvent 的使用。

using (var resetEvent = new ManualResetEvent(false))
{
    ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
    var extendedImage = new ExtendedImage();
    extendedImage.LoadingCompleted += (s, e) => resetEvent.Set();
    extendedImage.LoadingFailed += (s, e) => resetEvent.Set();
    extendedImage.SetSource(gifStream);
    resetEvent.WaitOne(TimeSpan.FromSeconds(5));

    // Check for timeout or error

    var enc = new JpegEncoder();
    var jpegStream = new MemoryStream();
    enc.Encode(extendedImage, jpegStream);
    ...

}

Replace the use of the ManualResetEvent for async code.

using (var resetEvent = new ManualResetEvent(false))
{
    ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
    var extendedImage = new ExtendedImage();
    extendedImage.LoadingCompleted += (s, e) => resetEvent.Set();
    extendedImage.LoadingFailed += (s, e) => resetEvent.Set();
    extendedImage.SetSource(gifStream);
    resetEvent.WaitOne(TimeSpan.FromSeconds(5));

    // Check for timeout or error

    var enc = new JpegEncoder();
    var jpegStream = new MemoryStream();
    enc.Encode(extendedImage, jpegStream);
    ...

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文