110,539
社区成员
发帖
与我相关
我的任务
分享
[DllImport("avicap32.dll")]
public static extern IntPtr capCreateCaptureWindowA(string 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 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);
[DllImport("User32.dll")]
public static extern bool DestroyWindow(int hndw);
这些是CameraBase类里引入视频API的方法
/// <summary>
/// 打开摄像头。
/// </summary>
public void Open()
{
this.fWindowPtr = CameraBase.capCreateCaptureWindowA("0", 0x50000000, 0, 0, this.fWidth, this.fHeight, this.fControlPtr, 0);
//连接摄像头
if (this.capDriverConnect(this.fWindowPtr, 0))
{
CameraBase.SendMessage(this.fWindowPtr, 0x435, -1, 0);
this.capPreviewRate(this.fWindowPtr, 66);
CameraBase.SendMessage(this.fWindowPtr, 0x432, -1, 0);
this.capPreview(this.fWindowPtr, true);
CameraBase.SetWindowPos(this.fWindowPtr, 1, 0, 0, this.fWidth, this.fHeight, 6);
this.fFrameEventHandler = new CameraBase.FrameEventHandler(FrameCallBack);
this.capSetCallbackOnFrame(this.fWindowPtr, this.fFrameEventHandler);
}
}
这里的this.fControlPtr是一个Panel控件的窗口句柄