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 >}