Solved

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

Posted on 2004-03-26
2
3,748 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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

13 Experts available now in Live!

Get 1:1 Help Now