C # simple Turn off camera

Source: Internet
Author: User

        Const short WM_CAP = 1024;        const int wm_cap_driver_connect = Wm_cap + 10;        const int wm_cap_driver_disconnect = Wm_cap + 11;        const int wm_cap_edit_copy = Wm_cap + 30;        const int Wm_cap_set_preview = Wm_cap + 50;        const int wm_cap_set_previewrate = Wm_cap + 52;        const int Wm_cap_set_scale = Wm_cap + 53;        const int ws_child = 0x40000000;        const int ws_visible = 0x10000000;        Const short Swp_nomove = 2;        Const short swp_nosize = 1;        Const short Swp_nozorder = 4;        Const short Hwnd_bottom = 1;        int iDevice = 0;        int Hhwnd;  [System.Runtime.InteropServices.DllImport ("user32", EntryPoint = "SendMessageA")] static extern int SendMessage (int        hwnd, int wmsg, int wParam, [MarshalAs (Unmanagedtype.asany)] object lParam); [System.Runtime.InteropServices.DllImport ("user32", EntryPoint = "SetWindowPos")] static extern int SetWindowPos (in T hwnd, int hwndinsertafter, int x,int y, int cx, int cy, int wflags);        [System.Runtime.InteropServices.DllImport ("user32")] static extern bool DestroyWindow (int hndw); [System.Runtime.InteropServices.DllImport ("Avicap32.dll")] static extern int Capcreatecapturewindowa (string Lpszwin        downame, int dwstyle, int x, int y, int nwidth, int nheight, int hwndparent, int nID); [System.Runtime.InteropServices.DllImport ("Avicap32.dll")] static extern bool Capgetdriverdescriptiona (short wdrive        R, string lpszName, int cbname, string lpszver, int cbver);            private void Openpreviewwindow () {int iheight = 600;            int iwidth = 800; Open Preview window in picturebox//Hhwnd = Capcreatecapturewindowa (idevice.tostr ING (), (ws_visible |            Ws_child), 0, 0, iwidth, iheight, PicCapture.Handle.ToInt32 (), 0); Connect to Device//if (SendMessage (Hhwnd, Wm_cap_driver_connect, IDevice, 0) = = 1) {////Set The preview scale/S                Endmessage (Hhwnd, Wm_cap_set_scale, 1, 0); Set the preview rate in milliseconds//SendMessage (Hhwnd, wm_cap_set_p                Reviewrate, 66, 0); Start previewing the image from the camera//SendMessage (Hhwnd, Wm_cap                _set_preview, 1, 0);  Resize window to fit in PictureBox//SetWindowPos (Hhwnd, Hwnd_bottom, 0, 0, iwidth, iheight, (Swp_nomove |            Swp_nozorder));                } else {////Error Connecting to device close window            DestroyWindow (Hhwnd);            }} private void Closepreviewwindow () {/////Disconnect from device SendmEssage (Hhwnd, Wm_cap_driver_disconnect, IDevice, 0);        Close window//DestroyWindow (Hhwnd); The private void Button1_Click (object sender, EventArgs e) {iDevice = 0;//int.            Parse (Device_number_textbox.text);        Openpreviewwindow (); }

  

C # simple Turn off camera

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.