C # capture video head (source code)

xiaoxiao2021-03-05  26

C # video capture program

Using system;

Using system.Runtime.InteropServices;

Namespace Wuyin.ShoesManager

{

///

/// vediocapture's summary description.

///

Public class vediocapture

{

Private int hcapturem;

Private bool isunload = false;

Public vediocapture ()

{

}

[DLLIMPORT ("avicap32.dll")]]]]]

Private Static Extern Int CapcreateCaptureWindow (String String ", int DWStyle, Int X, int y, int width, int hotht, int hwdparent, int nid)

[DLLIMPORT ("User32.dll")]]]]]

Private static extern int desundMessage (int HWnd, int WMSG, int WPARAM, INT LPARAM);

[DLLIMPORT ("User32.dll")]]]]]

Private Static Extern Int SendMessage (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, 0, 0, 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)

{

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 ()

{

IF (! isunload)

{

THIS.UnLoad ();

}

}

}

}

转载请注明原文地址:https://www.9cbs.com/read-32417.html

New Post(0)