Exemplo n.º 1
0
        /// <summary>
        /// 检查是否有视频设备
        /// </summary>
        /// <returns></returns>
        public bool CheckWebcamExist()
        {
            byte[] lpszName = new byte[100];
            byte[] lpszVer  = new byte[100];
            VideoAPI.capGetDriverDescription(0, lpszName, 100, lpszVer, 100);

            caphwnd = VideoAPI.capCreateCaptureWindow(lpszName, VideoAPI.WS_CHILD | VideoAPI.WS_VISIBLE, 0, 0, this.width, this.height, this.controlhwnd, 1);

            if (caphwnd == null)
            {
                return(false);
            }

            int  index     = 0;
            bool isconnect = VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_DRIVER_CONNECT, 0, 0);

            while (!isconnect)
            {
                isconnect = VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_DRIVER_CONNECT, 0, 0);
                if (++index <= 10)
                {
                    continue;
                }
            }
            if (isconnect == false)
            {
                VideoAPI.CloseHandle(caphwnd);
                return(false);
            }
            else
            {
                VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_DRIVER_DISCONNECT, 0, 0);
                return(true);
            }
        }
Exemplo n.º 2
0
 public bool GrabImage(IntPtr hWndC, string path)
 {
     if (caphwnd != null)
     {
         return(VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_SAVEDIB, 0, path));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 关闭视频设备
 /// </summary>
 /// <returns></returns>
 public bool StopWebcam()
 {
     if (caphwnd != null)
     {
         isstart = false;
         return(VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_DRIVER_DISCONNECT, 0, 0));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 启动视频设备
        /// </summary>
        /// <returns></returns>
        public bool StartWebcam()
        {
            byte[] lpszName = new byte[100];
            byte[] lpszVer  = new byte[100];
            VideoAPI.capGetDriverDescription(0, lpszName, 100, lpszVer, 100);

            caphwnd = VideoAPI.capCreateCaptureWindow(lpszName, VideoAPI.WS_CHILD | VideoAPI.WS_VISIBLE, 0, 0, this.width, this.height, this.controlhwnd, 1);

            if (caphwnd == null)
            {
                return(false);
            }

            //解决在Win7系统下摄像头获取不到问题
            int  index     = 0;
            bool isconnect = VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_DRIVER_CONNECT, 0, 0);

            while (!isconnect)
            {
                isconnect = VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_DRIVER_CONNECT, 0, 0);
                if (++index <= 10)
                {
                    continue;
                }
            }
            if (isconnect == false)
            {
                VideoAPI.CloseHandle(caphwnd);
                return(false);
            }

            if (VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_SET_PREVIEWRATE, 66, 0) == false)
            {
                return(false);
            }

            if (VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_SET_PREVIEW, true, 0) == false)
            {
                return(false);
            }

            if (VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_SET_SCALE, 1, 0) == false)
            {
                return(false);
            }

            isstart = true;
            return(true);
        }
Exemplo n.º 5
0
 public bool StopRecordVideo()
 {
     return(VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_STOP, 0, 0));
 }
Exemplo n.º 6
0
 public bool StartRecordVideo(string path)
 {
     VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_FILE_SET_CAPTURE_FILE, 0, path);
     VideoAPI.SendMessage(caphwnd, VideoAPI.WM_CAP_SEQUENCE, 0, 0);
     return(true);
 }
Exemplo n.º 7
0
 public void CopyToClipBorad()
 {
     VideoAPI.SendMessage(caphwnd, VideoAPI.WM_COPYTOCLIPBORAD, 0, 0);
 }