C#摄像头编程

本文介绍了使用C#编程操作摄像头的方法,包括打开、关闭摄像头,抓取图像,录像,以及调整摄像头设置。通过调用avicap32.dll库,实现了如设置预览比例、捕获帧率等功能。
摘要由CSDN通过智能技术生成

一。类

public class VideoAPI
    {
        [DllImport("avicap32.dll")]
        public static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);
        [DllImport("avicap32.dll")]
        public static extern bool capGetDriverDescriptionA(short wDriver, byte[] lpszName, int cbName, byte[] lpszVer, int cbVer);
        [DllImport("User32.dll")]
        public static extern bool SendMessage(IntPtr hWnd, int wMsg, bool wParam, int lParam);
        [DllImport("User32.dll")]
        public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, int lParam);

        [DllImport("user32")]
        public static extern bool DestroyWindow(IntPtr hWnd);
               

        #region
        //        // 开始定义消息参数  整数型
const  avicap32='avicap32.dll';

//public const int WM_CAP_START= WM_USER=1024;

start of unicode messages
//public const int WM_CAP_UNICODE_START=            WM_USER+100; //开始

//public const int WM_CAP_GET_CAPSTREAMPTR=         (WM_CAP_START+  1); //获得 CAPSTR EAMPTR

//public const int WM_CAP_SET_CALLBACK_ERROR=       (WM_CAP_START+  2); //设置收回错误
//public const int WM_CAP_SET_CALLBACK_STATUS=      (WM_CAP_START+  3); //设置收回状态

        public const int WM_CAP_SET_CALLBACK_YIELD = (WM_CAP_START + 4); //设置收回出产
        public const int WM_CAP_SET_CALLBACK_FRame = (WM_CAP_START + 5); //设置收回结构
        //public const int WM_CAP_SET_CALLBACK_VIDEOSTREAM = (WM_CAP_START + 6); //设置收回视频流
        public const int WM_CAP_SET_CALLBACK_WAVESTREAM = (WM_CAP_START + 7); //设置收回视频波流
        public const int WM_CAP_GET_USER_DATA = (WM_CAP_START + 8); //获得使用者数据
        public const int WM_CAP_SET_USER_DATA = (WM_CAP_START + 9); //设置使用者数据

//public const int WM_CAP_DRIVER_CONNECT          =(WM_CAP_START+  10); //驱动程序连接
//public const int WM_CAP_DRIVER_DISCONNECT       =(WM_CAP_START+  11); //断开启动程序连接

//public const int WM_CAP_DRIVER_GET_NAME         =(WM_CAP_START+  12); //获得驱动程序名字
//public const int WM_CAP_DRIVER_GET_VERSION      =(WM_CAP_START+  13); //获得驱动程序版本

//public const int WM_CAP_DRIVER_GET_CAPS         =(WM_CAP_START+  14); //获得驱动程序帽子

//public const int WM_CAP_FILE_SET_CAPTURE_FILE    =(WM_CAP_START+  20); //设置捕获文件
//public const int WM_CAP_FILE_GET_CAPTURE_FILE    =(WM_CAP_START+  21); //获得捕获文件
//public const int WM_CAP_FILE_SAVEAS              =(WM_CAP_START+  23); //另存文件为
//public const int WM_CAP_FILE_SAVEDIB             =(WM_CAP_START+  25); //保存文件

out of order to save on ifdefs
//public const int WM_CAP_FILE_ALLOCATE           =(WM_CAP_START+  22); //分派文件
//public const int WM_CAP_FILE_SET_INFOCHUNK      =(WM_CAP_START+ 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值