开发者

view gif image in image UI control windows phone 7

开发者 https://www.devze.com 2023-03-31 11:52 出处:网络
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));

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 l开发者_如何转开发oad 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));*

        }
    }


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

}

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号