Showvideo C # camera driver

Source: Internet
Author: User
Using system;
Using system. Collections. Generic;
Using system. text;
Using system. runtime. interopservices;


Namespace webcamera
{
ClassShowvideo
{
//Showvideo CILS
[Dllimport ("Avicap32.dll")]
Public static extern intptr capcreatecapturew.wa (byte [] lpszwindowname, int dwstyle, int X, int y, int nwidth, int nheight, intptr hwndparent, int NID );
[Dllimport ("Avicap32.dll")]
Public static extern bool capgetdriverdescriptiona (short wdriver, byte [] lpszname, int cbname, byte [] lpszver, int cbver );
[Dllimport ("user32.dll")]
Public static extern bool sendmessage (intptr hwnd, int wmsg, bool wparam, int lparam );
[Dllimport ("user32.dll")]
Public static extern bool sendmessage (intptr hwnd, int wmsg, short wparam, int lparam );
[Dllimport ("user32.dll")]
Public static extern bool sendmessage (intptr hwnd, int wmsg, short wparam, frameeventhandler lparam );
[Dllimport ("user32.dll")]
Public static extern bool sendmessage (intptr hwnd, int wmsg, int wparam, ref bitmapinfo lparam );
[Dllimport ("user32.dll")]
Public static extern int setwindowpos (intptr hwnd, int hwndinsertafter, int X, int y, int CX, int cy, int wflags );
[Dllimport ("Avicap32.dll")]
Public static extern int capgetvideoformat (intptr hwnd, intptr psvideoformat, int wsize );

// Constants
Public const int wm_user = 0x400;
Public const int ws_child = 0x40000000;
Public const int ws_visible = 0x10000000;
Public const int swp_nomove = 0x2;
Public const int swp_nozorder = 0x4;
Public const int wm_cap_driver_connect = wm_user + 10;
Public const int wm_cap_driver_disconnect = wm_user + 11;
Public const int wm_cap_set_callback_frame = wm_user + 5;
Public const int wm_cap_set_preview = wm_user + 50;
Public const int wm_cap_set_previewrate = wm_user + 52;
Public const int wm_cap_set_videoformat = wm_user + 45;

// Structures
[Structlayout (layoutkind. Sequential)]
Public struct videohdr
{
[Financialas (unmanagedtype. I4)]
Public int lpdata;
[Financialas (unmanagedtype. I4)]
Public int dwbufferlength;
[Financialas (unmanagedtype. I4)]
Public int dwbytesused;
[Financialas (unmanagedtype. I4)]
Public int dwtimecaptured;
[Financialas (unmanagedtype. I4)]
Public int dwuser;
[Financialas (unmanagedtype. I4)]
Public int dwflags;
[Financialas (unmanagedtype. byvalarray, sizeconst = 4)]
Public int [] dwreserved;
}

[Structlayout (layoutkind. Sequential)]
Public struct bitmapinfoheader
{
[Financialas (unmanagedtype. I4)]
Public int32 bisize;
[Financialas (unmanagedtype. I4)]
Public int32 biwidth;
[Financialas (unmanagedtype. I4)]
Public int32 biheight;
[Financialas (unmanagedtype. I2)]
Public short biplanes;
[Financialas (unmanagedtype. I2)]
Public short bibitcount;
[Financialas (unmanagedtype. I4)]
Public int32 bicompression;
[Financialas (unmanagedtype. I4)]
Public int32 bisizeimage;
[Financialas (unmanagedtype. I4)]
Public int32 bixpelspermeter;
[Financialas (unmanagedtype. I4)]
Public int32 biypelspermeter;
[Financialas (unmanagedtype. I4)]
Public int32 biclrused;
[Financialas (unmanagedtype. I4)]
Public int32 biclrimportant;
}

[Structlayout (layoutkind. Sequential)]
Public struct bitmapinfo
{
[Financialas (unmanagedtype. struct, sizeconst = 40)]
Public bitmapinfoheader bmiheader;
[Financialas (unmanagedtype. byvalarray, sizeconst = 1024)]
Public int32 [] bmicolors;
}

Public Delegate void frameeventhandler (intptr lwnd, intptr lpvhdr );

// Public methods
Public static object getstructure (intptr, valuetype structure)
{
Return marshal. ptrtostructure (PTR, structure. GetType ());
}

Public static object getstructure (int ptr, valuetype structure)
{
Return getstructure (New intptr (PTR), structure );
}

Public static void copy (intptr, byte [] data)
{
Marshal. Copy (PTR, Data, 0, Data. Length );
}

Public static void copy (int ptr, byte [] data)
{
Copy (New intptr (PTR), data );
}

Public static int sizeof (object structure)
{
Return marshal. sizeof (structure );
}

}
}

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.