This article drives the camera with the Avicap32.dll library. Due to grab, video features.
Using system;
Using system.Runtime.InteropServices;
Using system.drawing;
Using system.drawing.image;
Namespace;
Using system.Runtime.InteropServices;
Using system.drawing;
Using system.drawing.image;
Namespace Pickhead
{
///
/// A class that controls the camera
/// summary>
Public Class Pick
{
Private const Int WM_USER = 0x400;
Private const Int ws_child = 0x40000000;
Private const Int ws_visible = 0x10000000;
Private const INT WM_CAP_START = WM_USER;
Private const INT WM_CAP_STOP = WM_CAP_START 68;
Private const INT WM_CAP_DRIVER_CONNECT = WM_CAP_START 10;
Private const INT WM_CAP_DRIVER_DISCONNECT = WM_CAP_START 11;
Private const Int WM_CAP_SAVEDIB = WM_CAP_START 25;
Private const INT WM_CAP_GRAB_FRAME = WM_CAP_START 60;
Private const INT WM_CAP_SEQUENCE = WM_CAP_START 62;
Private const INT WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START 20;
Private const INT WM_CAP_SEQUENCE_NOFILE = WM_CAP_START 63;
Private const INT WM_CAP_SET_OVERLAY = WM_CAP_START 51;
Private const INT WM_CAP_SET_PREVIEW = WM_CAP_START 50;
Private const INT WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START 6;
Private const INT WM_CAP_SET_CALLBACK_ERROR = WM_CAP_START 2;
Private const INT WM_CAP_SET_CALLBACK_STATUSA = WM_CAP_START 3;
Private const INT WM_CAP_SET_CALLBACK_FRAME = WM_CAP_START 5;
Private const INT WM_CAP_SET_SCALE = WM_CAP_STARE = WM_CAP_START 53;
Private const INT WM_CAP_SET_PREVIEWRATE = WM_CAP_START 52;
PRIVATE INTPTR HWNDC;
PRIVATE BOOL BSTAT = FALSE
Private INTPTR MCONTROLPTR;
PRIVATE INT MWIDTH;
Private int maht; private int mlef;
PRIVATE INT MTOP;
///
/// Initialize the camera
/// summary>
/// Handle of the control param>
/// Start the left side of the display param>
/// Start the displayed upper margin param>
/// Width to display param>
/// The length to display param>
Public Pick (INTPTR HANDLE, INT LEFT, INT TOP, INT WIDTH, INTHEIGHT)
{
Mcontrolptr = handle;
MWIDTH = Width;
MeiHEight = Height;
MLEFT = LEFT;
Mtop = TOP;
}
[DLLIMPORT ("avicap32.dll")]]]]]
Private static extern INTPTR CAPCREATECAPTUREWINDOWA (Byte [] LPSZWindowname, int DWStyle, Int x, int y, int nwidth, int nheight, intptr hwndparent, int NID;
[DLLIMPORT ("avicap32.dll")]]]]]
Private Static Extern Int CapGetVideoFormat (INTPTR HWND, INTPTR PSVideoFormat, int wsize);
[DLLIMPORT ("User32.dll")]]]]]
Private Static Extern Bool SendMessage (INTPTR HWND, INT WMSG, INT WPARAM, long lparam);
///
/// Start display image
/// summary>
Public void start ()
{
IF (bstat)
Return;
Bstat = true;
Byte [] lpszname = new byte [100];
HWNDC = CapcreateCaptureWindowa (Lpszname, WS_CHILD | WS_VISIBLE, MLEFT, MTOP, MWIDTH, MLEFT, MCONTROLPTR, 0);
IF (hwndc.toint32 ()! = 0)
{
SendMessage (HWNDC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
SendMessage (HWNDC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);
SendMessage (HWNDC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0);
SendMessage (HWNDC, WM_CAP_DRIVER_CONNECT, 0, 0);
SendMessage (HWNDC, WM_CAP_SET_SCALE, 1, 0);
SendMessage (HWNDC, WM_CAP_SET_PREVIEWRATE, 66, 0);
SendMessage (HWNDC, WM_CAP_SET_OVERLAY, 1, 0);
SendMessage (HWNDC, WM_CAP_SET_PREVIEW, 1, 0);}
Return;
}
///
/// Stop display
/// summary>
Public void stop ()
{
SendMessage (HWNDC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
Bstat = false;
}
///
/// grasp
/// summary>
/// To save the path of the BMP file param>
Public void grabimage (String Path)
{
INTPTR HBMP = Marshal.StringTohglobalansi (PATH);
SendMessage (HWNDC, WM_CAP_SAVEDIB, 0, HBMP.TOINT64 ());
}
///
/// video
/// summary>
/// To save the path of the AVI file param>
Public void Kinescope (String Path)
{
INTPTR HBMP = Marshal.StringTohglobalansi (PATH);
SendMessage (HWNDC, WM_CAP_FILE_SET_CAPTURE_FILEA, 0, HBMP.TOINT64 ());
SendMessage (HWNDC, WM_CAP_SEQUENCE, 0, 0);
}
///
/// Stop recording
/// summary>
Public void stopkinescope ()
{
SendMessage (HWNDC, WM_CAP_STOP, 0, 0);
}
}
}