Display simple Gif

Jan 14, 2012 at 9:35 PM

Hi I'm very new to silverlight and can anyone write a simple code for displaying Gif using ImageTools? I tried to look everywhere but cannot really understand, I know

 ExtendedImage desert = new ExtendedImage();           

desert.LoadingCompleted += loadcomplete;                       

desert.UriSource = new Uri("/Clock.gif", UriKind.Relative);

 

but how am I going to display it into my Image Control? Thanks.

Jan 19, 2012 at 11:42 PM
Edited Jan 19, 2012 at 11:45 PM

Hi,

I Have the same problem! I tried to use the Source Property of the AnimatedImage Control but when i click the button nothing happens.

Here's the code: 

 private void Button_Click(object sender, RoutedEventArgs e)
        {
            Decoders.AddDecoder<GifDecoder>();
            ExtendedImage addGIF = new ExtendedImage();
            addGIF.UriSource = new Uri("/test.gif", UriKind.Relative);
            addGIF.LoadingCompleted += On_Load;
        }

        private void On_Load(object sender, EventArgs e)
        {
            test.Source = sender as ExtendedImage;
        } 

 

 

Jan 20, 2012 at 6:47 AM
Is this event On_Load called? The gif decoder only supports 90% of the gif images, probably your images uses some exotic formats.

Also make sure to download the latest source code version.

Am 20.01.2012 01:43, schrieb Karebes:

From: Karebes

Hi,

I Have the same problem! I tried to use the Source Property of the AnimatedImage Control but when i click the button nothing happens.

Here's the code:

void Button_Click(object sender, RoutedEventArgs e)

{

Decoders.AddDecoder<GifDecoder>();

ExtendedImage addGIF = new ExtendedImage();

addGIF.UriSource = new Uri("/test.gif", UriKind.Relative);

addGIF.LoadingCompleted += On_Load;

}

private void On_Load(object sender, EventArgs e) { test.Source = sender as ExtendedImage; }


Jan 20, 2012 at 9:56 AM
Edited Jan 20, 2012 at 9:57 AM

Actually i had two problems:

a) the first problem was with the threads.

b) I didn't add reference to ImageTools.IO.Png

Bacillus the code to get it work:

using ImageTools.IO;
using ImageTools.IO.Gif;
using ImageTools;
using ImageTools.Controls;

.....


private void Button_Click(object sender, RoutedEventArgs e)
{
       Decoders.AddDecoder();
       addGIF = new ExtendedImage();
       addGIF.UriSource = new Uri("/test.gif", UriKind.Relative);
       addGIF.LoadingCompleted += On_Load;
}

private void On_Load(object sender, EventArgs e)
{
       Dispatcher.BeginInvoke(() =>
       {
             test.Source = addGIF;
       });
}
++ADD REFERNCE TO ImageTools.IO.Png
Feb 24, 2012 at 3:35 AM

I solved this problem as follows:

MainPage.xaml:

<UserControl

...

  xmlns:it="clr-namespace:ImageTools.Controls;assembly=ImageTools.Controls"

x:Class="BannerIndex.MainPage" Width="262" Height="572">
<Grid x:Name="LayoutRoot" Background="White">       

<it:AnimatedImage x:Name="gifImage" Stretch="Uniform" AutoSize="False" />

</Grid></UserControl>

MainPage.xaml.cs:

using ImageTools.IO;

using ImageTools.IO.Gif;

using ImageTools;

...

public MainPage() { 

Decoders.AddDecoder<GifDecoder>();           

 InitializeComponent();           

ExtendedImage addGIF = new ExtendedImage();         

addGIF.UriSource = new Uri("001.gif", UriKind.Relative);

gifImage.Source = addGIF; 

...


Mar 22, 2012 at 11:33 AM

No matter which variation of this I try, I get an InvalidOperationException on:

Contract.Requires<InvalidOperationException>(stream.CanSeek);

It seems as if the stream is somehow bad, but I can't find out why.

Coordinator
Mar 22, 2012 at 11:36 AM

Hi,

when I started with the project I only made it for Silverlight and realized that the web streams supporting seeking. The gif decoder needs this feature.

It seems that the windows phone version does not support webstreams where CanSeek is true.


Therefore loading fails. Unfortunatly I have no simple workaround and not so much time to solve it.

Mar 22, 2012 at 6:09 PM

Ah, at least it's not just me being stupid :-P

Thanks for the reply.

I thought of perhaps trying to download the file and load it locally (which actually does seem to work), but the downloading fails on about the same issue and I haven't found a solution for that yet. Thanks anyway.