?
Solved

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

Posted on 2004-03-26
2
Medium Priority
?
3,968 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
codewiz51 earned 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

752 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