Monday, January 23, 2012

GIF image Silverlight

Here's the reason for no GIF support as given by a member of the Silverlight development team (see here):

We don’t want to take the hit for another codec. It may only be a little bit of download time—but our mandate is small and fast and every little bit counts. We are also hesitant to support .gif because it implies support for animated .gif, which we decided would have to be integrated into our animation scheme somehow—and that will be a lot of work. Looking from Flash perspective, Flash does not support .gif either. However, as of present, this is something being evaluated, but no date has been announced

Solution / Work around

Strip Images From Animated Gif see here


Create a silver light application




Code Behind

namespace gifplayer
{
public partial class MainPage : UserControl
{
private int iNumber = 0;
private DispatcherTimer timer = new DispatcherTimer();

public MainPage()
{
InitializeComponent();

timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
timer.Tick += new EventHandler(Tick);
image1.Source = new BitmapImage(new Uri("gif/frame0.jpeg", UriKind.Relative));
iNumber = 0;
timer.Start();
}

private void Tick(object sender, EventArgs e)
{

if (iNumber == 90)
{
image1.Source = new BitmapImage(new Uri("gif/frame90.jpeg", UriKind.Relative));
iNumber = 0;
image1.Source = new BitmapImage(new Uri("gif/frame0.jpeg", UriKind.Relative));
}
else
{
image1.Source = new BitmapImage(new Uri("gif/frame" + iNumber.ToString() + ".jpeg", UriKind.Relative));
iNumber++;
}


}

}
}

Run the application to see the moving gif animation

As we can strip gif image into different frames depending upon thegif images number of frame change the iNumber value

Some areas to be noted

time span given is 100 ms that can vary
in first cycle image flickers

No comments: