标签:call 视频流 erro 保存 disco finally path byte source
如有雷同,不胜荣幸,若转载,请注明
这个是大众普通方法,鉴于有网友和朋友问相同的问题。在这里将我的拙劣的代码关键部分贴出来。以便帮助很多其它的朋友们,不足之处甚多,我能够学习,交流,请教阁下
废话到此。直接上代码
private const int WS_CHILD = 0x40000000; //1073741824
/// <summary>
/// 开启视频摄像头
/// </summary>
/// <returns></returns>
public static void Start()
{
if (bWorkStart)
{
return;
}
byte[] lpszName = new byte[100];
try
{
hWndC = Windows.capCreateCaptureWindow(lpszName, WS_CHILD | WS_VISIBLE, mLeft, mTop, mWidth, mHeight, mControlPtr, 0);
if (hWndC.ToInt32() != 0)
{
Windows.SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0); //设置返回视频流
Windows.SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0); //设置返回错误
Windows.SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0); //设置返回状态
//=====================这条比較慢=======================
Windows.SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0); //设备连接
//=====================================================
//Windows.SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0); //開始捕捉
//=====================================================
Windows.SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0); //设置比例
Windows.SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0); //设置预览速度
Windows.SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0); //设置叠加
Windows.SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0); //设置预览
bWorkStart = true;
}
//return true;
}
catch (Exception)
{
//return false;
}
//finally
//{
//写日志 Global.log.Write( “SendMessage “);
//LogClass.WriteLog("SendMessage");
//}
}
/// <summary>
/// 关闭视频摄像头
/// </summary>
public static void Stop()
{
Windows.SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
bWorkStart = false;
}
/// <summary>
/// 抓图或者拍照。然后保存到指定路径下
/// </summary>
/// <param name="path">要保存bmp文件的路径</param>
public static void GrabImage(string path)
{
IntPtr hBmp = Marshal.StringToHGlobalAnsi(path);
Windows.SendMessage(hWndC, WM_CAP_SAVEDIB, 0, hBmp.ToInt32()); //0x41e
}
/// <summary>
/// 捕捉图像拷贝到剪切板
/// </summary>
/// <returns></returns>
public static bool CopyToClipBoard()
{
return Windows.SendMessage(hWndC, WM_CAP_CAPTURE_IMAGE_CLIPBOARD, 0, 0);
}
标签:call 视频流 erro 保存 disco finally path byte source
原文地址:http://www.cnblogs.com/gccbuaa/p/6790564.html