我看过这个article,我想知道我是否可以用图像列表替换画笔?
这是从brush创建AVI
文件的代码:
private void buttonCreateVideo_Click(object sender, EventArgs e)
{
int width = 640;
int height = 480;
VideoFileWriter writer = new VideoFileWriter();
writer.Open("code-bude_test_video.avi", width, height, 25, VideoCodec.MPEG4, 100000);
Bitmap image = new Bitmap(width, height);
Graphics g = Graphics.FromImage(image);
g.FillRectangle(Brushes.Black, 0, 0, width, height);
Brush[] brushList = new Brush[] { Brushes.Green, Brushes.Red, Brushes.Yellow, Brushes.Pink, Brushes.LimeGreen };
for (int i = 0; i < listBox1.Items.Count; i++)
{
Application.DoEvents();
g.FillRectangle(brushList[i % 5], (i % width) * 2, (i % height) * 0.5f, i % 30, i % 30);
g.FillRectangle(brushList[i % 5], (i % width) * 2, (i % height) * 2, i % 30, i % 30);
g.FillRectangle(brushList[i % 5], (i % width) * 0.5f, (i % height) * 2, i % 30, i % 30);
g.Save();
writer.WriteVideoFrame(image);
}
writer.Close();
}
这是我的清单:
private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
DialogResult result = fbd.ShowDialog();
if (result == DialogResult.OK)
{
NumericComparer ns = new NumericComparer();
string[] array1 = Directory.GetFiles(fbd.SelectedPath, "*.Jpeg");
ns = new NumericComparer(); // new object
Array.Sort(array1, ns);
listBox1.Items.Clear();
foreach (string name in array1)
{
listBox1.Items.Add(name);
}
}
}
我只需要从文件夹中添加图片并将其保存在.avi
视频
答案 0 :(得分:1)
我认为是这样的:
for(int i = 0; i < listBox1.Items.Count; i++)
{
Application.DoEvents();
var frame = new Bitmap(name);
g.DrawImage(frame, 0, 0, width, height);
writer.WriteVideoFrame(image);
}