也许这是一个愚蠢的问题,但不能管理下一个问题。 我正在按钮上放gif动画。但它循环顺序,永不停止。 我需要在一圈完成后停下来。如何在Button控件上使用动画GIF?
Bitmap boom = new Bitmap("boom.gif");
b[ship2.Column, ship2.Row].Image = boom;
我的代码有什么问题?
也许这是一个愚蠢的问题,但不能管理下一个问题。 我正在按钮上放gif动画。但它循环顺序,永不停止。 我需要在一圈完成后停下来。如何在Button控件上使用动画GIF?
Bitmap boom = new Bitmap("boom.gif");
b[ship2.Column, ship2.Row].Image = boom;
我的代码有什么问题?
您的代码没有问题。
循环数存储在图像元数据中。所以基本上你需要提供已禁用循环或edit it with some kind of gif editor.
编辑GIF
,因为它忽视了GIF元数据和无休止的循环下去,你可以使用http://gif-explode.com/得到的最后一帧gif。然后测量动画循环的mileseconds,做这样的事情:
我会建议你使用pictureBox
和尝试这个代码(如果可以实现)
// this starts animation
System.Drawing.ImageAnimator.Animate(pictBox.Image, OnFrameChanged);
// this stops animation
System.Drawing.ImageAnimator.StopAnimate(pictBox.Image, OnFrameChanged);
private void OnFrameChanged(object sender, EventArgs e)
{
// conditions
}
但是,这实际上,不是一个按钮,对吧? – user3281887
@ user3281887这是图片如果你想继续使用按钮,请按照cvsguimaraes的回答。 – Marek
是的,我可能需要使用按钮,但无论如何,谢谢。 – user3281887
你可以使用一系列图像,而不是GIF的。您可以使用计时器并将间隔设置为所需的速度。计时器将在每个抽搐中改变按钮的图像。你将需要GIF的帧。你可以去 - >http://gif-explode.com/。把gif放在那里,并获得每一帧。然后,您可以将图像放在图像列表中。我想你想要点击按钮时动画开始。
int i = 0;
private void timer1_Tick(object sender, EventArgs e)
{
if (i == imageList1.Images.Count)
{
timer1.Stop();
i = 0;
}
button1.Image = imageList1.Images[i];
i++;
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
}
我已经做了所有的事情,如你所说,如果在Internet Explorer中启动此gif,那么它运行一次。但在C#中它仍然是永远运行:( – user3281887
似乎他忽略了这个元数据,我会改进答案。 – cvsguimaraes
@ user3281887答案更新 – cvsguimaraes