摄像头编程WindowsAPI - avicap32.dll 参数详解

  1. // 窗口消息 WM_CAP... 哪个是送到 AVICAP 窗口  
  2. // ------------------------------------------------------------------  
  3. // 开始定义消息参数 整数型  
  4. const avicap32='avicap32.dll';  
  5. WM_CAP_START= WM_USER=1024;  
  6. // start of unicode messages  
  7. WM_CAP_UNICODE_START=            WM_USER+100; //开始  
  8. WM_CAP_GET_CAPSTREAMPTR=         (WM_CAP_START+ 1); //获得 CAPSTR EAMPTR  
  9. WM_CAP_SET_CALLBACK_ERROR=       (WM_CAP_START+ 2); //设置回调错误  
  10. WM_CAP_SET_CALLBACK_STATUS=      (WM_CAP_START+ 3); //设置回调状态  
  11. WM_CAP_SET_CALLBACK_YIELD=       (WM_CAP_START+ 4); //设置回调出产  
  12. WM_CAP_SET_CALLBACK_FRAME=       (WM_CAP_START+ 5); //设置回调结构  
  13. WM_CAP_SET_CALLBACK_VIDEOSTREAM= (WM_CAP_START+ 6); //设置回调视频流  
  14. WM_CAP_SET_CALLBACK_WAVESTREAM= (WM_CAP_START+ 7); //设置回调视频波流  
  15. WM_CAP_GET_USER_DATA            =(WM_CAP_START+ 8); //获得使用者数据  
  16. WM_CAP_SET_USER_DATA           =(WM_CAP_START+ 9) ; //设置使用者数据  
  17. WM_CAP_DRIVER_CONNECT          =(WM_CAP_START+ 10); //驱动程序连接  
  18. WM_CAP_DRIVER_DISCONNECT       =(WM_CAP_START+ 11); //断开启动程序连接  
  19. WM_CAP_DRIVER_GET_NAME         =(WM_CAP_START+ 12); //获得驱动程序名字  
  20. WM_CAP_DRIVER_GET_VERSION      =(WM_CAP_START+ 13); //获得驱动程序版本  
  21. WM_CAP_DRIVER_GET_CAPS         =(WM_CAP_START+ 14); //获得驱动程序性能  
  22. WM_CAP_FILE_SET_CAPTURE_FILE    =(WM_CAP_START+ 20); //设置捕获文件的文件名  
  23. WM_CAP_FILE_GET_CAPTURE_FILE    =(WM_CAP_START+ 21); //获得捕获文件的文件名  
  24. WM_CAP_FILE_SAVEAS              =(WM_CAP_START+ 23); //另存文件为  
  25. WM_CAP_FILE_SAVEDIB             =(WM_CAP_START+ 25); //保存文件  
  26. // out of order to save on ifdefs  
  27. WM_CAP_FILE_ALLOCATE           =(WM_CAP_START+ 22); //分派文件, 为捕获文件建一个指定大小的文件  
  28. WM_CAP_FILE_SET_INFOCHUNK      =(WM_CAP_START+ 24); //设置开始文件  
  29. WM_CAP_EDIT_COPY               =(WM_CAP_START+ 30); //编辑复制,把图象考入剪贴板  
  30. WM_CAP_SET_AUDIOFORMAT         =(WM_CAP_START+ 35); //设置音频格式  
  31. WM_CAP_GET_AUDIOFORMAT         =(WM_CAP_START+ 36); //捕获音频格式  
  32. WM_CAP_DLG_VIDEOFORMAT         =(WM_CAP_START+ 41); //1065 打开视频格式设置对话框, 选择数字视频的框架大小和视频图像的色深,以及捕获视频图像的压缩格式。  
  33. WM_CAP_DLG_VIDEOSOURCE         =(WM_CAP_START+ 42); //1066 打开属性设置对话框,设置对比度、亮度等。(视频源对话框) 选择视频输入通道和视频图像的动态参数。  
  34. WM_CAP_DLG_VIDEODISPLAY        =(WM_CAP_START+ 43); //1067 打开视频显示对话框  
  35. WM_CAP_GET_VIDEOFORMAT         =(WM_CAP_START+ 44); //1068 获得视频格式  
  36. WM_CAP_SET_VIDEOFORMAT         =(WM_CAP_START+ 45); //1069 设置视频格式  
  37. WM_CAP_DLG_VIDEOCOMPRESSION    =(WM_CAP_START+ 46); //1070 打开压缩设置对话框  
  38. WM_CAP_SET_PREVIEW             =(WM_CAP_START+ 50); //设置预览模式  
  39. WM_CAP_SET_OVERLAY             =(WM_CAP_START+ 51); //设置覆盖  
  40. WM_CAP_SET_PREVIEWRATE         =(WM_CAP_START+ 52); //设置预览模式下图像的帧速度  
  41. WM_CAP_SET_SCALE               =(WM_CAP_START+ 53); //设置预览视频的缩放比例  
  42. WM_CAP_GET_STATUS              =(WM_CAP_START+ 54); //获得状态  
  43. WM_CAP_SET_SCROLL              =(WM_CAP_START+ 55); //设置卷  
  44. WM_CAP_GRAB_FRame              =(WM_CAP_START+ 60); //逮捕结构  
  45. WM_CAP_GRAB_FRame_NOSTOP       =(WM_CAP_START+ 61); //停止逮捕结构,截取当前图象  
  46. WM_CAP_SEQUENCE                =(WM_CAP_START+ 62); //次序,捕捉到文件  
  47. WM_CAP_SEQUENCE_NOFILE         =(WM_CAP_START+ 63); //没有文件  
  48. WM_CAP_SET_SEQUENCE_SETUP      =(WM_CAP_START+ 64); //设置当前捕获的帧频率  
  49. WM_CAP_GET_SEQUENCE_SETUP      =(WM_CAP_START+ 65); //获得当前捕获的帧频率  
  50. WM_CAP_SET_MCI_DEVICE          =(WM_CAP_START+ 66); //设置媒体控制接口  
  51. WM_CAP_GET_MCI_DEVICE          =(WM_CAP_START+ 67); //获得媒体控制接口  
  52. WM_CAP_STOP                    =(WM_CAP_START+ 68); //停止捕捉  
  53. WM_CAP_ABORT                   =(WM_CAP_START+ 69); //异常中断  
  54. WM_CAP_SINGLE_FRame_OPEN       =(WM_CAP_START+ 70); //打开单一的结构  
  55. WM_CAP_SINGLE_FRame_CLOSE      =(WM_CAP_START+ 71); //关闭单一的结构  
  56. WM_CAP_SINGLE_FRame            =(WM_CAP_START+ 72); //单一的结构  
  57. WM_CAP_PAL_OPEN                =(WM_CAP_START+ 80); //打开视频  
  58. WM_CAP_PAL_SAVE                =(WM_CAP_START+ 81); //保存视频  
  59. WM_CAP_PAL_PASTE               =(WM_CAP_START+ 82); //粘贴视频  
  60. WM_CAP_PAL_AUTOCREATE          =(WM_CAP_START+ 83); //自动创造  
  61. WM_CAP_PAL_MANUALCREATE        =(WM_CAP_START+ 84); //手动创造  
  62. // Following added post VFW 1.1  
  63. WM_CAP_SET_CALLBACK_CAPCONTROL =(WM_CAP_START+ 85); // 设置收回的错误  
  64. WM_CAP_END                      =WM_CAP_SET_CALLBACK_CAPCONTROL;  
  65.   
  66.  using System;  
  67.   using System.Runtime.InteropServices;  
  68.   using System.Drawing;  
  69.   using System.Drawing.Imaging;  
  70.   
  71.   namespace PickHead  
  72.   {  
  73.   /// <summary>  
  74.   /// 一个控制摄像头的类  
  75.   /// </summary>  
  76.   public class Pick  
  77.   {  
  78.   private const int WM_USER = 0x400;  
  79.   private const int WS_CHILD = 0x40000000;  
  80.   private const int WS_VISIBLE = 0x10000000;  
  81.   private const int WM_CAP_START = WM_USER;  
  82.   private const int WM_CAP_STOP = WM_CAP_START + 68;  
  83.   private const int WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;  
  84.   private const int WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;  
  85.   private const int WM_CAP_SAVEDIB = WM_CAP_START + 25;  
  86.   private const int WM_CAP_GRAB_FRAME = WM_CAP_START + 60;  
  87.   private const int WM_CAP_SEQUENCE = WM_CAP_START + 62;  
  88.   private const int WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20;  
  89.   private const int WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63;  
  90.   private const int WM_CAP_SET_OVERLAY =WM_CAP_START+ 51;   
  91.   private const int WM_CAP_SET_PREVIEW =WM_CAP_START+ 50;   
  92.   private const int WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6;  
  93.   private const int WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2;  
  94.   private const int WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3;  
  95.   private const int WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5;  
  96.   private const int WM_CAP_SET_SCALE=WM_CAP_START+ 53;  
  97.   private const int WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52;   
  98.   private IntPtr hWndC;  
  99.   private bool bStat = false;  
  100.     
  101.   private IntPtr mControlPtr;  
  102.   private int mWidth;  
  103.   private int mHeight;  
  104.   private int mLeft;  
  105.   private int mTop;  
  106.     
  107.   /// <summary>  
  108.   /// 初始化摄像头  
  109.   /// </summary>  
  110.   /// <param name="handle">控件的句柄</param>  
  111.   /// <param name="left">开始显示的左边距</param>  
  112.   /// <param name="top">开始显示的上边距</param>  
  113.   /// <param name="width">要显示的宽度</param>  
  114.   /// <param name="height">要显示的长度</param>  
  115.   public Pick(IntPtr handle, int left, int top, int width,int height)  
  116.   {  
  117.   mControlPtr = handle;  
  118.   mWidth = width;  
  119.   mHeight = height;  
  120.   mLeft = left;  
  121.   mTop = top;  
  122.   }  
  123.   
  124.   [DllImport("avicap32.dll")]   
  125.   private static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);  
  126.     
  127.   [DllImport("avicap32.dll")]  
  128.   private static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize );  
  129.   [DllImport("User32.dll")]   
  130.   private static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, long lParam);  
  131.   
  132.   /// <summary>  
  133.   /// 开始显示图像  
  134.   /// </summary>  
  135.   public void Start()  
  136.   {  
  137.   if (bStat)  
  138.   return;  
  139.     
  140.   bStat = true;  
  141.   byte[] lpszName = new byte[100];  
  142.     
  143.   hWndC = capCreateCaptureWindowA(lpszName,WS_CHILD|WS_VISIBLE ,mLeft,mTop,mWidth,mHeight,mControlPtr,0);  
  144.   
  145.   if (hWndC.ToInt32() != 0)  
  146.   {  
  147.   SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);  
  148.   SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);  
  149.   SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);  
  150.   SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);  
  151.   SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);  
  152.   SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);  
  153.   SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);  
  154.   SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);  
  155.   }  
  156.   
  157.   return;  
  158.   
  159.   }  
  160.   
  161.   /// <summary>  
  162.   /// 停止显示  
  163.   
  164.   /// </summary>  
  165.   public void Stop()  
  166.   {  
  167.   SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);  
  168.   bStat = false;  
  169.   }  
  170.   
  171.   /// <summary>  
  172.   /// 抓图  
  173.   /// </summary>  
  174.   /// <param name="path">要保存bmp文件的路径</param>  
  175.   public void GrabImage(string path)  
  176.   {  
  177.     
  178.   IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);  
  179.   SendMessage(hWndC,WM_CAP_SAVEDIB,0,hBmp.ToInt64());  
  180.   
  181.   }  
  182.   
  183.   /// <summary>  
  184.   /// 录像  
  185.   /// </summary>  
  186.   /// <param name="path">要保存avi文件的路径</param>  
  187.   public void Kinescope(string path)  
  188.   {  
  189.   IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);  
  190.   SendMessage(hWndC,WM_CAP_FILE_SET_CAPTURE_FILEA,0,hBmp.ToInt64());  
  191.   SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);  
  192.   }  
  193.   
  194.   /// <summary>  
  195.   /// 停止录像  
  196.   /// </summary>  
  197.   public void StopKinescope()  
  198.   {  
  199.   SendMessage(hWndC, WM_CAP_STOP, 0, 0);  
  200.   }  
  201.   
  202.   }  
  203.   }  
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值