C# 操作網路攝影機

來源:互聯網
上載者:User

標籤:call   視頻流   erro   儲存   disco   finally   path   byte   source   

如有雷同,不勝榮幸,若轉載,請註明

這個是福士普通方法,鑒於有網友和朋友問相同的問題。在這裡將我的拙劣的代碼關鍵區段貼出來。以便協助很多其它的朋友們,不足之處甚多,我能夠學習,交流,請教閣下

廢話到此。直接上代碼

private const int WS_CHILD = 0x40000000;  //1073741824
        private const int WS_VISIBLE = 0x10000000;  //268435456
        private const int WM_USER = 0x400;  //1024
        private const int WM_CAP_START = WM_USER;  //1024
        private const int WM_CAP_STOP = WM_CAP_START + 68;  //1092
        private const int WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10;  //1034
        private const int WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11;  //1035
        private const int WM_CAP_SAVEDIB = WM_CAP_START + 25;  //1049
        private const int WM_CAP_GRAB_FRAME = WM_CAP_START + 60;  //1084
        private const int WM_CAP_SEQUENCE = WM_CAP_START + 62;  //1086
        private const int WM_CAP_FILE_SET_CAPTRUE_FILEA = WM_CAP_START + 20;  //1044
        private const int WM_CAP_SEQUENCE_NOFILE = WM_CAP_START + 63;  //1087
        private const int WM_CAP_CAPTURE_IMAGE_CLIPBOARD = WM_CAP_START + 30;  //1054 複製捕捉的映像到剪下板
        private const int WM_CAP_SET_OVERLAY = WM_CAP_START + 51;  //1075
        private const int WM_CAP_SET_PREVIEW = WM_CAP_START + 50;  //1074
        private const int WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START + 6;  //1030
        private const int WM_CAP_SET_CALLBACK_ERROR = WM_CAP_START + 2;  //1026
        private const int WM_CAP_SET_CALLBACK_STATUSA = WM_CAP_START + 3;  //1027
        private const int WM_CAP_SET_CALLBACK_FRAME = WM_CAP_START + 5;  //1029
        private const int WM_CAP_SET_SCALE = WM_CAP_START + 53;  //1077
        private const int WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52;  //1076
        private const int WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42;  //1066 選擇網路攝影機


/// <summary>
        /// 開啟視頻網路攝影機
        /// </summary>
        /// <returns></returns>
        public static void Start()
        {
            if (bWorkStart)
            {
                return;
            }
            byte[] lpszName = new byte[100];
            try
            {
                hWndC = Windows.capCreateCaptureWindow(lpszName, WS_CHILD | WS_VISIBLE, mLeft, mTop, mWidth, mHeight, mControlPtr, 0);
                if (hWndC.ToInt32() != 0)
                {
                    Windows.SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);  //設定返回視頻流
                    Windows.SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);  //設定返回錯誤
                    Windows.SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);  //設定返回狀態
                    //=====================這條比較慢=======================
                    Windows.SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);  //裝置串連
                    //=====================================================
                    //Windows.SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);  //開始捕捉
                    //=====================================================
                    Windows.SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);  //設定比例
                    Windows.SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);  //設定預覽速度
                    Windows.SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);  //設定疊加
                    Windows.SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);  //設定預覽


                    bWorkStart = true;
                }
                //return true;
            }
            catch (Exception)
            {
                //return false;
            }
            //finally
            //{
                //寫日誌  Global.log.Write( “SendMessage “);
                //LogClass.WriteLog("SendMessage");
            //}
        }

/// <summary>
        /// 關閉視頻網路攝影機
        /// </summary>
        public static void Stop()
        {
            Windows.SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
            bWorkStart = false;
        }

/// <summary>
        /// 抓圖或者拍照。然後儲存到指定路徑下
        /// </summary>
        /// <param name="path">要儲存bmp檔案的路徑</param>
        public static void GrabImage(string path)
        {
            IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
            Windows.SendMessage(hWndC, WM_CAP_SAVEDIB, 0, hBmp.ToInt32());  //0x41e
        }

/// <summary>
        /// 捕捉映像拷貝到剪下板
        /// </summary>
        /// <returns></returns>
        public static bool CopyToClipBoard()
        {
            return Windows.SendMessage(hWndC, WM_CAP_CAPTURE_IMAGE_CLIPBOARD, 0, 0); 
        }

C# 操作網路攝影機

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.