1

我有一个 Windows 应用程序,可以在发布到 Web 服务器之前预览图像列表,而无需使用 WPF 当用户按下下一个或上一个时,我需要在图片之间设置动画(滑动或淡入淡出或翻转)

谢谢哈姆扎

4

1 回答 1

4

ImageAnimator您可以使用类为图像设置动画

例子:

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));
    }
于 2012-10-31T09:07:06.853 回答