我如何更改此程序以动画化10张图像 [英] how can i change this program to anamate 10 images
本文介绍了我如何更改此程序以动画化10张图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//假设所有10张图像均已在某处读取
// assume all 10 images has already read somewhere
using System;
using System.Drawing;
using System.Windows.Forms;
namespace AnamateImage
{
//public class animateImage : Form
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Create a Bitmpap Object.
Bitmap animatedImage = new Bitmap("mywateranamate01.bmp");
//Image[] animatedImage = new Image[10];// assumed it is already has read
bool currentlyAnimating = false;
//int count = 0, len = 10;
//This method begins the animation.
public void AnimateImage()
{
if (!currentlyAnimating)
{
//Begin the animation only once.
ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged));
//ImageAnimator.Animate(animatedImage[count], 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));
}
}
}
推荐答案
将表单转换为 ^ ].
这是一些有关如何执行此操作的信息:使用.NET Framework开发自定义Windows窗体控件 [^ ]
如果您拥有适合您的产品,那么这应该很方便:)
问候
Espen Harlinn
Convert the form to a UserControl[^].
Here is some info on how to do this: Developing Custom Windows Forms Controls with the .NET Framework[^]
If what you''ve got works for you, than this should be a snap :)
Regards
Espen Harlinn
您的代码使用了bmp图片.此格式不是多帧图像(除非他们在不告诉我的情况下更改了格式:).ImageAnimator
需要多帧图像.
多帧图像格式包括"gif"和"tiff".
此 [ NGif,.NET的动画GIF编码器 [搜索文章 [
Your code uses a bmp image. This format is not a multi-frame image (unless they have changed the format without telling me :) ). TheImageAnimator
requires a multiple-frame image.
The multi-frame image formats include ''gif'' and ''tiff''.
This[^] demonstrates creating a tiff image.
NGif, Animated GIF Encoder for .NET[^] is one of several articles here on CP that shows how to create a gif format image from several images. (search the articles[^] for more, if that doesn''t help.)
这篇关于我如何更改此程序以动画化10张图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文