C # operating Camera

Source: Internet
Author: User

If there is similar, it is honored, if reproduced, please specify

This is the general public method, in view of netizens and friends ask the same question, here will my poor code key part of the post, in order to help more friends, the shortcomings of a lot, I can learn, exchange, ask Your Excellency

Nonsense to this, directly on the code

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 copy the captured image to the clipboard
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 Select Camera

<summary>
Turn on the video camera
</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); Set the return video stream
Windows.sendmessage (HWNDC, wm_cap_set_callback_error, 0, 0); Set return error
Windows.sendmessage (HWNDC, Wm_cap_set_callback_statusa, 0, 0); Set the return status
===================== this one is slower =======================
Windows.sendmessage (HWNDC, wm_cap_driver_connect, 0, 0); Device connection
//=====================================================
Windows.sendmessage (HWNDC, wm_cap_sequence, 0, 0); Start capturing
//=====================================================
Windows.sendmessage (HWNDC, Wm_cap_set_scale, 1, 0); Set scale
Windows.sendmessage (HWNDC, Wm_cap_set_previewrate, 66, 0); Set the preview speed
Windows.sendmessage (HWNDC, Wm_cap_set_overlay, 1, 0); Set Overlay
Windows.sendmessage (HWNDC, Wm_cap_set_preview, 1, 0); Set preview


Bworkstart = true;
}
return true;
}
catch (Exception)
{
return false;
}
Finally
//{
Write Log Global.log.Write ("SendMessage");
Logclass.writelog ("SendMessage");
//}
}

<summary>
Turn off the video camera
</summary>
public static void Stop ()
{
Windows.sendmessage (HWNDC, wm_cap_driver_disconnect, 0, 0);
Bworkstart = false;
}

<summary>
Grab a picture or take a picture and save it to the specified path
</summary>
<param name= "path" > Path to save BMP file </param>
public static void Grabimage (string path)
{
IntPtr hbmp = marshal.stringtohglobalansi (path);
Windows.sendmessage (HWNDC, Wm_cap_savedib, 0, Hbmp.toint32 ()); 0x41e
}

<summary>
Capture image Copy to clipboard
</summary>
<returns></returns>
public static bool CopyToClipboard ()
{
Return Windows.sendmessage (HWNDC, Wm_cap_capture_image_clipboard, 0, 0);
}

C # operating 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.