C # video capturing

Source: Internet
Author: User

Q: C # capturing videos \
A:
Using system;
Using system. runtime. interopservices;

Namespace wuyin. shoesmanager
{
/// <Summary>
/// Summary of vediocapture.
/// </Summary>
Public class vediocapture
{
Private int hcapturem;
Private bool isunload = false;
Public vediocapture ()
{
}
[Dllimport ("avicap32.dll")]
Private Static extern int capcreatecapturewindow (string strwindowname, int dwstyle, int X, int y, int width, int height, int hwdparent, int NID );
[Dllimport ("user32.dll")]
Private Static extern int sendmessage (INT hwnd, int wmsg, int wparam, int lparam );
[Dllimport ("user32.dll")]
Private Static extern int sendmessage (INT hwnd, int wmsg, int wparam, string lparam );
[Dllimport ("kernel32.dll")]
Private Static extern bool closehandle (INT hobject );
Public bool initialize (system. Windows. Forms. Control acontainer, int intwidth, int intheight)
{
Hcapturem = capcreatecapturewindow ("", 0x40000000 | 0x10000000, intwidth, intheight, acontainer. Handle. toint32 (), 1 );
If (hcapturem = 0) return false;

Int ret = sendmessage (hcapturem, 1034, 0, 0 );
If (ret = 0)
{
Closehandle (hcapturem );
Return false;
}
// Wm_cap_set_preview
Ret = sendmessage (hcapturem, 1074, 1, 0 );
If (ret = 0)
{
This. Unload ();
Return false;
}
// Wm_cap_set_scale
Ret = sendmessage (hcapturem, 1077, 1, 0 );
If (ret = 0)
{
This. Unload ();
Return false;
}
// Wm_cap_set_previewrate
Ret = sendmessage (hcapturem, 1076, 66, 0 );
If (ret = 0)
{
This. Unload ();
Return false;
}
Return true;
}

Public void singleframebegin ()
{
//
Int ret = sendmessage (hcapturem, 1094, 0, 0 );
}
Public void singleframeend ()
{
//
Int ret = sendmessage (hcapturem, 1095, 0, 0 );
}

Public void singleframemode ()
{
// Wm_cap_grab_frame
Int ret = sendmessage (hcapturem, 1084, 0, 0 );
// Wm_cap_set_preview
// Int ret = sendmessage (hcapturem, 1074, 0, 0 );
// Wm_cap_single_frame
// Ret = sendmessage (hcapturem, 1096, 0, 0 );
}
Public void previewmode ()
{
Int ret = sendmessage (hcapturem, 1074, 1, 0 );
}

Public void unload ()
{
Int ret = sendmessage (hcapturem, 1035, 0, 0 );
Closehandle (this. hcapturem );
Isunload = true;
}

Public void copytoclipborad ()
{
Int ret = sendmessage (hcapturem, 1054, 0, 0 );
}

Public void showformatdialog ()
{
Int ret = sendmessage (hcapturem, 1065, 0, 0 );
}
Public void savetodib (string filename)
{
Int ret = sendmessage (hcapturem, 1049, 0, filename );
}

Public void showdisplaydialog ()
{
Int ret = sendmessage (hcapturem, 1067, 0, 0 );
}
Public System. Drawing. Image getcaptureimage ()
{
System. Windows. Forms. idataobject idata = system. Windows. Forms. clipboard. getdataobject ();
System. Drawing. Image retimage = NULL;
If (idata! = NULL)
{
If (idata. getdatapresent (system. Windows. Forms. dataformats. Bitmap ))
{
Retimage = (system. Drawing. Image) idata. getdata (system. Windows. Forms. dataformats. Bitmap );
}
Else if (idata. getdatapresent (system. Windows. Forms. dataformats. Dib ))
{
Retimage = (system. Drawing. Image) idata. getdata (system. Windows. Forms. dataformats. Dib );
}
}
Return retimage;
}

~ Vediocapture ()
{< br> If (! Isunload)
{< br> This. Unload ();
}< BR >}

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.