



免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C#调用摄像头拍摄,截图,视频 (2013-01-29 14:35:43)分类:C#cs类:using System.Runtime.InteropServices;using System.Drawing.Imaging;namespace WindowsFormsApplication2class Pickprivate const int WM_USER = 0x400;private const int WS_CHILD = 0x40000000;private const int WS_VISIBLE = 0x10000000;private const int WM_CAP_START = WM_USER;private const int WM_CAP_STOP = WM_CAP_START + 68;private const int WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;private const int WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;private const int WM_CAP_SAVEDIB = WM_CAP_START + 25;private const int WM_CAP_GRAB_FRAME = WM_CAP_START + 60;private const int WM_CAP_SEQUENCE = WM_CAP_START + 62;private const int WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;private const int WM_CAP_SEQUENCE_NOFILE = WM_CAP_START + 63;private const int WM_CAP_SET_OVERLAY = WM_CAP_START + 51;private const int WM_CAP_SET_PREVIEW = WM_CAP_START + 50;private const int WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START + 6;private const int WM_CAP_SET_CALLBACK_ERROR = WM_CAP_START + 2;private const int WM_CAP_SET_CALLBACK_STATUSA = WM_CAP_START + 3;private const int WM_CAP_SET_CALLBACK_FRAME = WM_CAP_START + 5;private const int WM_CAP_SET_SCALE = WM_CAP_START + 53;private const int WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52;private IntPtr hWndC;private bool bStat = false;private IntPtr mControlPtr;private int mWidth;private int mHeight;private int mLeft;private int mTop;/ / 初始化摄像头 / / 控件的句柄 / 开始显示的左边距 / 开始显示的上边距 / 要显示的宽度 / 要显示的长度 public Pick(IntPtr handle, int left, int top, int width, int height)mControlPtr = handle;mWidth = width;mHeight = height;mLeft = left;mTop = top;DllImport(avicap32.dll)private static extern IntPtr capCreateCaptureWindowA(byte lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);DllImport(avicap32.dll)private static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize);DllImport(User32.dll)private static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);/ / 开始显示图像 / public void Start()if (bStat)return;bStat = true;byte lpszName = new byte100;hWndC = capCreateCaptureWindowA(lpszName, WS_CHILD | WS_VISIBLE, mLeft, mTop, mWidth, mHeight, mControlPtr, 0);if (hWndC.ToInt32() != 0)SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);return;/ / 停止显示 / public void Stop()SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);bStat = false;/ / 抓图 / / 要保存bmp文件的路径 public void GrabImage(string path)/ public void GrabImage( ) IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);SendMessage(hWndC, WM_CAP_SAVEDIB, 0, hBmp.ToInt32();/ / 录像 / / 要保存avi文件的路径 public void Kinescope(string path)IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);SendMessage(hWndC, WM_CAP_FILE_SET_CAPTURE_FILEA, 0, hBmp.ToInt32();SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);/ / 停止录像 / public void StopKinescope()SendMessage(hWndC, WM_CAP_STOP, 0, 0); aspx:namespace WindowsFormsApplication2public partial class Form1 : FormPick pick;public Form1()InitializeComponent();private void button1_Click(object sender, EventArgs e) /启动摄像头pick = new Pick(panel1.Handle, 0, 0, panel1.Width, panel1.Height);pick.Start();pictureBox1.ImageLocation = null; /清空pictureBox1private void button2_Click(object sender, EventArgs e) /停止摄像头pick.Stop();private void button3_Click(object sender, EventArgs e) /退出界面if (MessageBox.Show(退出本系统?, 提示, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.OK)Application.Exit();private void button4_Click(object sender, EventArgs e) /保存截图string path;SaveFileDialog sdf1 = new SaveFileDialog();sdf1.Filter = 图片*.bmp;*.jpg;.j
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 45505.5-2025平板显示器基板玻璃测试方法第5部分:光电性能
- 机械考试题库及答案解析
- 森林火灾知识培训
- 森林扑火知识培训方案课件
- 2025年建筑设计公司招聘项目管理经理面试题集与答案
- 肠梗阻的护理常规考试试题及答案
- 2025年注册验船师资格考试(A级船舶检验专业案例分析)复习题及答案一
- 2025年乡村道路交通安全管理员招聘考试指南
- 2025年物流行业运营经理面试题集萃
- 2025年非遗传承师刺绣方向中级考试复习资料与
- 2025年福建闽投工业区开发有限公司招聘笔试参考题库含答案解析
- 建筑工程常见施工质量通病及防治措施图文
- 家庭房产分割协议书
- 北师大版《心理健康》九年级上册全套教学课件
- 《液压与气动控制》课件
- 邮政快递员技能大赛理论考试题库(含答案)
- 《电动航空器电推进系统技术规范》
- 结肠造瘘还纳术手术配合
- 2024年山东省建筑施工企业主要负责人A类考试题库及答案(典型题)
- 特种设备目录新旧对照表
- 2024年初一英语阅读理解专项练习及答案
评论
0/150
提交评论