Solved

In C# How do stop an animated GIF after a single loop

Posted on 2004-03-26
2
3,788 Views
Last Modified: 2011-09-20
My C# program runs an animated GIFs.  Is there any way to have it stop the animated GIF after a single loop (or a specified number of loops) through all the frames in the GIF?  

Currently, I'm running the animated GIF's in a small PictureBox control that is on my main form:  

   this.AnimationGIF = new System.Windows.Forms.PictureBox();
   AnimationGIF.Image = Image.FromFile(GIF filename);

The above will display and run the animated GIF continuously in the picture box.  I currently stop it by running the above as a thread and stopping it after a fixed number of seconds.   I would like it to stop automatically after a set number of loops through all the frames.

Thanks.
0
Comment
Question by:khrispy
2 Comments
 
LVL 2

Accepted Solution

by:
codewiz51 earned 250 total points
ID: 10693351
Normally, the looping is set during the construction of the gif.  You should be able to load the file into an animated gif editor and set the looping.  GIF89a supports extensions for looping once, n times or never.

You can also check out the System.Drawing.ImageAnimator class.  It offers some specialized methods you can use to pace your gif and turn off animation using the static StopAnimate method.
0
 

Author Comment

by:khrispy
ID: 10719013
Codewiz51,

Thanks for you suggestion although it didn't quite work.  I had given you the points (you can keep them) before completely testing out your suggestion in my code.  I went ahead and created some animated GIFs that loops only once.  Unfortunatley when they are loaded onto the picturebox control they run continuously.  The control seems to ignore the looping property of the GIF.  The same problem occurs using the ImageAnimator class.  

When I open up the animated GIFs on a web browser they run only a single loop as designed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now