如何在不显示SaveFileDialog的情况下保存快照?

时间:2014-03-06 09:10:45

标签: c#

我想从网络摄像头拍摄快照并将其保存在给定的路径中。网络摄像头应该在给定的时间段后启动。这是我尝试过的代码正常但我不需要弹出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);

        }



    }

1 个答案:

答案 0 :(得分: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);