2014-03-06 59 views
-2

我想從網絡攝像頭拍快照,並將其保存在一個給定的path.The攝像頭一個給定的時間period.This後應該開始是我曾嘗試它的代碼工作正常,但我不需要在文件彈出SaveFileDialog正在保存。如何在不顯示SaveFileDialog的情況下保存快照?請幫助.....如何在不顯示SaveFileDialog的情況下保存快照?

private void btnStartPic_Click(object sender, EventArgs e) 
    { 
     int delay = Convert.ToInt32(numericUpDown1.Value); 
     int miliseconds = delay * 1000; 
     Thread.Sleep(miliseconds); 
     this.Refresh(); 

     cm = new VideoCaptureDevice(wcam[cmbDevice.SelectedIndex].MonikerString); 
     cm.NewFrame += new NewFrameEventHandler(cam_newFrame); 
     cm.Start(); 

     String path = txtBrowse.Text; 

     string currentDateTime = string.Format("text-{0:yyyy-MM-dd_hh-mm-ss-tt}.bin", DateTime.Now); 

     SaveFileDialog s = new SaveFileDialog(); 
     s.FileName = currentDateTime + ".jpg"; 
     s.DefaultExt = ".Jpg"; 
     s.Filter = currentDateTime + "(.jpg)|*.jpg"; 


     s.InitialDirectory = @path; 

     if (s.ShowDialog() == DialogResult.OK) 
     { 

      pictureBox1.Image.Save(s.FileName); 

     } 



    } 

回答

2

你有自己的答案:

pictureBox1.Image.Save(s.FileName); 

第一個參數是一個文件名,這樣你就可以用string提供,如果你想。

樣品:

pictureBox1.Image.Save(@"c:\test\picture.jpg"); 

pictureBox1.Image.Save(Path.Combine("folder", "filename")); 

string s = ... 

pictureBox1.Image.Save(s); 
+0

@ user3387002:既然你是新來的,請不要忘記標記了一個問題,如果回答的答案就足夠了。請參閱[FAQ#why-vote] –

+0

您需要更多幫助嗎?如果不是,請將其標記爲已回答,以解決此問題。 –

相關問題