C# How to stop animated gif from continually looping

雨燕双飞 提交于 2019-12-17 20:10:12

问题


I have an event that gets called when my app uses the internet. The event changes an animated gif composed of 7 frames. How do I make it only loop through the frames only once?

        private void trafficSendingActive(object sender, trafficEventArgs e)
        {
            txImage.Image = Properties.Resources.blip;
        }

回答1:


You could use the System.Drawing.ImageAnimator to start/stop the gif animation

// start
System.Drawing.ImageAnimator.Animate(txImage.Image, OnFrameChanged);

// stop
System.Drawing.ImageAnimator.StopAnimate(txImage.Image, OnFrameChanged);

private void OnFrameChanged(object sender, EventArgs e)
{
   // frame change
}



回答2:


You could always encapsulate the image/gif inside a Picturebox, and when you want the gif to stop, just set the Enabled property of the Picturebox to false.

Just a thought.




回答3:


You can extract single frame from that GIF image (non - animated) when the progress event is done,

txImage.Image = Image.FormFile("non-animated-frame-from-gif.jpg");

You can use this website to extract frame from gif : http://gif-explode.com/




回答4:


You can just use pictureBox.Enabled = false; if you want to stop the GIF & pictureBox.Enabled = true; when you want it to run the GIF.



来源:https://stackoverflow.com/questions/15647901/c-sharp-how-to-stop-animated-gif-from-continually-looping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!