免费预览已结束,剩余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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年广东舞蹈戏剧职业学院单招职业适应性考试题库含答案
- 2026年山西职业技术学院单招职业倾向性测试题库及答案1套
- 2026年新疆科技职业技术学院单招职业适应性考试题库附答案
- 2026年嘉兴南洋职业技术学院单招职业适应性考试题库附答案
- 2026年广西工程职业学院单招职业技能测试题库新版
- 2026年广西农业职业技术大学单招职业技能测试题库含答案
- 2026年四川建筑职业技术学院单招职业倾向性测试题库完美版
- 2026年郑州轨道工程职业学院单招职业技能测试题库必考题
- 2026年中级经济师之中级经济师金融专业考试题库300道附参考答案(b卷)
- 2025高平市人民医院招聘博士研究生及高级专业技术人才备考题库带答案解析
- 拖欠工程款上访信范文
- 【化 学】第六单元 碳和碳的氧化物单元试题卷-2024-2025学年九年级化学人教版(2024)上册
- 2024年碳纤维增强尼龙项目可行性研究报告
- 护理实习生的职业规划
- 【MOOC】数学文化十讲-南开大学 中国大学慕课MOOC答案
- 体育场馆跑道草坪改造及保养方案
- 种植烟叶采购合同模板
- 1.4.3 戴维南定理讲解
- 二年级乘除法口算题计算练习大全2000题(可直接打印)
- 洗浴中心储值卡会员规则
- 专业路灯计算书(带公式)
评论
0/150
提交评论