Exemplo n.º 1
0
 /// <summary>
 /// 停止录像
 /// </summary>
 public void StopKinescope()
 {
     if (State == CameraState.Scoping)
     {
         AviCap32Helper.SendMessage(_captureWindowHandle, AviCap32Helper.WM_CAP_STOP, 0, 0);
         State = CameraState.Opend;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 抓图保存到文件
 /// </summary>
 /// <param name="bmpPath">要保存bmp文件的路径</param>
 public void GrabImage(string bmpPath)
 {
     if (State != CameraState.Closed)
     {
         IntPtr hBmp = Marshal.StringToHGlobalAnsi(bmpPath);
         AviCap32Helper.SendMessage(_captureWindowHandle, AviCap32Helper.WM_CAP_FILE_SAVEDIB, 0, hBmp.ToInt32());
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 开始录像
 /// </summary>
 /// <param name="aviPath">要保存avi文件的路径</param>
 public void StartKinescope(string aviPath)
 {
     if (State == CameraState.Opend)
     {
         IntPtr hBmp = Marshal.StringToHGlobalAnsi(aviPath);
         AviCap32Helper.SendMessage(_captureWindowHandle, AviCap32Helper.WM_CAP_FILE_SET_CAPTURE_FILE, 0, hBmp.ToInt32());
         AviCap32Helper.SendMessage(_captureWindowHandle, AviCap32Helper.WM_CAP_SEQUENCE, 0, 0);
         State = CameraState.Scoping;
     }
 }
Exemplo n.º 4
0
 //收到帧时的处理
 private void FrameCallBack(IntPtr lwnd, IntPtr lpVHdr)
 {
     AviCap32Helper.VIDEOHDR videoHeader = new AviCap32Helper.VIDEOHDR();
     byte[] VideoData;
     videoHeader = (AviCap32Helper.VIDEOHDR)AviCap32Helper.GetStructure(lpVHdr, videoHeader);
     VideoData   = new byte[videoHeader.dwBytesUsed];
     AviCap32Helper.Copy(videoHeader.lpData, VideoData);
     if (this.RecievedFrame != null)
     {
         this.RecievedFrame(VideoData);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 启动摄像头
        /// </summary>
        public void Open()
        {
            if (State != CameraState.Closed)
            {
                return;
            }

            //创建视频窗口
            _captureWindowHandle = AviCap32Helper.capCreateCaptureWindowA(
                "",
                AviCap32Helper.WS_VISIBLE + AviCap32Helper.WS_CHILD,
                0,
                0,
                _windowWidth,
                _windowHeight,
                _controlHandle,
                0);
            //连接设备
            if (CapDriverConnect(_captureWindowHandle, 0))
            {
                //获得当前视频 CAPDRIVERCAPS定义了捕获驱动器的能力,如有无视频叠加能力、有无控制视频源、视频格式的对话框等
                //AviCap32Helper.SendMessage(_captureWindowHandle, AviCap32Helper.WM_CAP_DRIVER_GET_CAPS, AviCap32Helper.SizeOf(_capDriverCAPS), ref _capDriverCAPS);
                //获得当前视频流的尺寸 存入CapStatus结构
                AviCap32Helper.SendMessage(_captureWindowHandle, AviCap32Helper.WM_CAP_GET_STATUS, AviCap32Helper.SizeOf(_capStatus), ref _capStatus);
                //if (CameraConnected != null)
                //{
                //    CameraConnected(new CameraConntectedEventArgs()
                //    {
                //        ImageWidth = _capStatus.uiImageWidth,
                //        ImageHeight = _capStatus.uiImageHeight
                //    });
                //}

                _imageX      = (_windowWidth - _capStatus.uiImageWidth) / 2;
                _imageY      = (_windowHeight - _capStatus.uiImageHeight) / 2;
                _imageWidth  = Math.Min(_windowWidth, _capStatus.uiImageWidth);
                _imageHeight = Math.Min(_windowHeight, _capStatus.uiImageHeight);
                //调整视口的位置和大小
                AviCap32Helper.SetWindowPos(_captureWindowHandle, 0, _imageX, _imageY, _capStatus.uiImageWidth, _capStatus.uiImageHeight, 0);

                //设置视频格式
                //AviCap32Helper.BITMAPINFO bitmapInfo = new AviCap32Helper.BITMAPINFO();
                //bitmapInfo.bmiHeader = new AviCap32Helper.BITMAPINFOHEADER();
                //bitmapInfo.bmiHeader.biSize = AviCap32Helper.SizeOf(bitmapInfo.bmiHeader);
                //bitmapInfo.bmiHeader.biWidth = 50;
                //bitmapInfo.bmiHeader.biHeight = 50;
                //bitmapInfo.bmiHeader.biPlanes = 1;
                //bitmapInfo.bmiHeader.biBitCount = 24;
                //CapSetVideoFormat(_captureWindowHandle, ref bitmapInfo, AviCap32Helper.SizeOf(bitmapInfo));

                //设置在PREVIEW模式下设定视频窗口的刷新率 设置每50毫秒显示一帧,即显示帧速为每秒20帧
                CapSetPreviewRate(_captureWindowHandle, 50);
                //打开预览视频的缩放功能
                //AviCap32Helper.SendMessage(_captureWindowHandle, AviCap32Helper.WM_CAP_SET_SCALE, 1, 0);
                CapSetPreview(_captureWindowHandle, true);

                _frameEventHandler = new AviCap32Helper.FrameEventHandler(FrameCallBack);
                CapSetCallbackFrame(_captureWindowHandle, _frameEventHandler);
                State = CameraState.Opend;
            }
            else
            {
                throw new Exception("无法连接摄像头");
            }
        }
Exemplo n.º 6
0
        //获取视频格式
        //private int CapGetVideoFormat(IntPtr hCapWnd, ref AviCap32Helper.BITMAPINFO BmpFormat, int CapFormatSize)
        //{
        //    return AviCap32Helper.capGetVideoFormat(hCapWnd, IntPtr.Zero, 0);
        //}

        //设置视频格式
        private bool CapSetVideoFormat(IntPtr hCapWnd, ref AviCap32Helper.BITMAPINFO BmpFormat, int CapFormatSize)
        {
            return(AviCap32Helper.SendMessage(hCapWnd, AviCap32Helper.WM_CAP_SET_VIDEOFORMAT, CapFormatSize, ref BmpFormat));
        }
Exemplo n.º 7
0
 //设置获取帧的回调
 private bool CapSetCallbackFrame(IntPtr lwnd, AviCap32Helper.FrameEventHandler lpProc)
 {
     return(AviCap32Helper.SendMessage(lwnd, AviCap32Helper.WM_CAP_SET_CALLBACK_FRAME, 0, lpProc));
 }
Exemplo n.º 8
0
 //设置预览Rate
 private bool CapSetPreviewRate(IntPtr lwnd, short wMS)
 {
     return(AviCap32Helper.SendMessage(lwnd, AviCap32Helper.WM_CAP_SET_PREVIEWRATE, wMS, 0));
 }
Exemplo n.º 9
0
 //设置预览
 private bool CapSetPreview(IntPtr lwnd, bool f)
 {
     return(AviCap32Helper.SendMessage(lwnd, AviCap32Helper.WM_CAP_SET_PREVIEW, f, 0));
 }
Exemplo n.º 10
0
 //断开设备连接
 private bool CapDriverDisconnect(IntPtr lwnd)
 {
     return(AviCap32Helper.SendMessage(lwnd, AviCap32Helper.WM_CAP_DRIVER_DISCONNECT, 0, 0));
 }
Exemplo n.º 11
0
 //连接设备
 private bool CapDriverConnect(IntPtr lwnd, short i)
 {
     return(AviCap32Helper.SendMessage(lwnd, AviCap32Helper.WM_CAP_DRIVER_CONNECT, i, 0));
 }