如何在不显示SaveFileDialog的情况下保存快照? [英] How to save snapshot without showing SaveFileDialog?

查看:68
本文介绍了如何在不显示SaveFileDialog的情况下保存快照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位大家好,我想从网络摄像头拍摄快照并将其保存在给定的路径中。网络摄像头应该在给定的时间段后启动。这是我试过的代码正常但我不需要弹出的代码文件保存时保存SaveFileDialog。如何在不显示SaveFileDialog的情况下保存快照?请帮助.....

Hello everybody,I want to take snapshot from the webcam and save it in a given path.The webcam should start after a given time period.This is the code I have tried it works properly but I don't need to popup SaveFileDialog when the file is saving.How do I save the snapshot without showing SaveFileDialog? Please help.....

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

            }

             

        }

推荐答案

只有从用户那里获取有效路径才需要SaveFileDialog。

当您已经知道路径时,您不需要SaveFileDialog。只需在字符串变量中构造文件名,并使用此路径和Save()方法。
A SaveFileDialog is only needed to get a valid path from the user.
When you already know the path, you don't need a SaveFileDialog. Just construct the filename in a string variable and use this path with the Save() method.


通过 @OriginalGriff 保存没有保存文件对话框的图像 [ ^ ]。


这篇关于如何在不显示SaveFileDialog的情况下保存快照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆