2014-03-13 25 views
0

我已經看到這個article,我想知道如果我可以用圖像列表替換畫筆嗎?用圖像清單替換畫筆?

這裏是創建一個從刷一個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視頻中添加圖像並保存

回答

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); 
}