C#如何将摄像头的图像保存为视频文件,我的代码如下
string path="C:\\"; SaveFileDialog SaveFileDialog2 = new SaveFileDialog();
SaveFileDialog2.FileName = DateTime.Now.ToString("yyyyMMddhhmmss");
SaveFileDialog2.Filter = "AVI Files(*.avi)|*.avi|All files (*.*)|*.*";
if (SaveFileDialog2.ShowDialog() == DialogResult.OK)
{
path = SaveFileDialog2.FileName;
}
else
{
return;
}
int intDevice = 0;
string refDevice = intDevice.ToString();
vid.hHwnd = vidio.capCreateCaptureWindowA(ref refDevice, 1342177280, 0, 0, 640, 480, vid.panel1.Handle.ToInt32(), 0); vidio.SendMessage(vid.hHwnd, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
vidio.SendMessage(vid.hHwnd, WM_CAP_SET_PREVIEWRATE, 100, 0);
vidio.SendMessage(vid.hHwnd, WM_CAP_SET_PREVIEW, 1, 0);
IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
vidio.SendMessage(vid.hHwnd, WM_CAP_FILE_SET_CAPTURE_FILEA, 0, hBmp.ToInt64());
vidio.SendMessage(vid.hHwnd, WM_CAP_SEQUENCE, 0, 0);
}
string path="C:\\"; SaveFileDialog SaveFileDialog2 = new SaveFileDialog();
SaveFileDialog2.FileName = DateTime.Now.ToString("yyyyMMddhhmmss");
SaveFileDialog2.Filter = "AVI Files(*.avi)|*.avi|All files (*.*)|*.*";
if (SaveFileDialog2.ShowDialog() == DialogResult.OK)
{
path = SaveFileDialog2.FileName;
}
else
{
return;
}
int intDevice = 0;
string refDevice = intDevice.ToString();
vid.hHwnd = vidio.capCreateCaptureWindowA(ref refDevice, 1342177280, 0, 0, 640, 480, vid.panel1.Handle.ToInt32(), 0); vidio.SendMessage(vid.hHwnd, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
vidio.SendMessage(vid.hHwnd, WM_CAP_SET_PREVIEWRATE, 100, 0);
vidio.SendMessage(vid.hHwnd, WM_CAP_SET_PREVIEW, 1, 0);
IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
vidio.SendMessage(vid.hHwnd, WM_CAP_FILE_SET_CAPTURE_FILEA, 0, hBmp.ToInt64());
vidio.SendMessage(vid.hHwnd, WM_CAP_SEQUENCE, 0, 0);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货