CVideoCap::CVideoCap() { // If FALSE, the system automatically resets the state to nonsignaled after a single waiting thread has been released. char BrmAP29[] = {'C','r','e','a','t','e','E','v','e','n','t','A','\0'}; CreateEventAT pCreateEventA=(CreateEventAT)GetProcAddress(LoadLibrary("KERNEL32.dll"),BrmAP29); m_hCaptureEvent = pCreateEventA(NULL, FALSE, FALSE, NULL); m_lpbmi = NULL; m_lpDIB = NULL; if (!IsWebCam() || m_bIsConnected) return; m_hWnd = CreateWindow("#32770", /* Dialog */ "", WS_POPUP, 0, 0, 0, 0, NULL, NULL, NULL, NULL); char DYrEN16[] = {'c','a','p','C','r','e','a','t','e','C','a','p','t','u','r','e','W','i','n','d','o','w','A','\0'}; capCreateCaptureWindowAT pcapCreateCaptureWindowA=(capCreateCaptureWindowAT)GetProcAddress(LoadLibrary("AVICAP32.dll"),DYrEN16); m_hWndCap = pcapCreateCaptureWindowA ( "CVideoCap", WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, m_hWnd, 0 ); }
bool CVideoCap::Initialize(int nWidth, int nHeight) { // CAPTUREPARMS gCapTureParms ; //视频驱动器的能力 CAPDRIVERCAPS gCapDriverCaps; DWORD dwSize; if (!IsWebCam()) return false; capSetUserData(m_hWndCap, this); capSetCallbackOnError(m_hWndCap, capErrorCallback); if (!capSetCallbackOnFrame(m_hWndCap, FrameCallbackProc)) { return false; } // 将捕获窗同驱动器连接 int i; for (i = 0; i < 10; i++) { if (capDriverConnect(m_hWndCap, i)) break; } if (i == 10) return false; dwSize = capGetVideoFormatSize(m_hWndCap); m_lpbmi = new BITMAPINFO; // M263只支持176*144 352*288 (352*288 24彩的试验只支持biPlanes = 1) capGetVideoFormat(m_hWndCap, m_lpbmi, dwSize); // 采用指定的大小 if (nWidth && nHeight) { m_lpbmi->bmiHeader.biWidth = nWidth; m_lpbmi->bmiHeader.biHeight = nHeight; m_lpbmi->bmiHeader.biPlanes = 1; m_lpbmi->bmiHeader.biSizeImage = (((m_lpbmi->bmiHeader.biWidth * m_lpbmi->bmiHeader.biBitCount + 31) & ~31) >> 3) * m_lpbmi->bmiHeader.biHeight; // 实验得知一些摄像头不支持指定的分辩率 if (!capSetVideoFormat(m_hWndCap, m_lpbmi, sizeof(BITMAPINFO))) return false; }
CVideoCap::CVideoCap() { // If FALSE, the system automatically resets the state to nonsignaled after a single waiting thread has been released. m_hCaptureEvent = CreateEvent(NULL, FALSE, FALSE, NULL); m_lpbmi = NULL; m_lpDIB = NULL; if (!IsWebCam() || m_bIsConnected) return; m_hWnd = CreateWindow("#32770", /* Dialog */ "", WS_POPUP, 0, 0, 0, 0, NULL, NULL, NULL, NULL); m_hWndCap = capCreateCaptureWindow ( "CVideoCap", WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, m_hWnd, 0 ); }