Solved

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

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

717 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