我有一个问题与动画gif图片框,它是不移动,由c#代码
本文关键字:代码 移动 问题 有一个 动画 gif | 更新日期: 2023-09-27 18:09:06
我有一个问题与图片框,我选择一个图像类型的动画gif,图片显示,但它不移动,通过c#代码
这可以帮助:动画方法
using System;
using System.Drawing;
using System.Windows.Forms;
public class animateImage : Form
{
//Create a Bitmpap Object.
Bitmap animatedImage = new Bitmap("SampleAnimation.gif");
bool currentlyAnimating = false;
//This method begins the animation.
public void AnimateImage()
{
if (!currentlyAnimating)
{
//Begin the animation only once.
ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged));
currentlyAnimating = true;
}
}
private void OnFrameChanged(object o, EventArgs e)
{
//Force a call to the Paint event handler.
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
//Begin the animation.
AnimateImage();
//Get the next frame ready for rendering.
ImageAnimator.UpdateFrames();
//Draw the next frame in the animation.
e.Graphics.DrawImage(this.animatedImage, new Point(0, 0));
}
public static void Main()
{
Application.Run(new animateImage());
}
}
你必须手动处理动画。这里有一个例子http://www.vcskicks.com/csharp_animated_gif2.php
编辑代码可以在这里:可以在Windows应用程序中显示GIF动画吗?