void WriteCameraImage (const char sCameraImg[]) { // Call capGrabFrame twice to flush images stored in the camera queue. This // makes the screen image more responsive to the current position of the // subject, especially when using slow stacked ASM models. // TODO does this slow down the frame rate and is there a better way of doing this? capGrabFrame(hgCapWnd); capGrabFrame(hgCapWnd); // now get the actual frame we want, and save it to disk capGrabFrame(hgCapWnd); capFileSaveDIB(hgCapWnd, sCameraImg); }
void __fastcall TForm1::Timer2Timer(TObject *Sender) { capGrabFrame(hWndC); bool capOK=capEditCopy(hWndC); // копируем кадр в буфер обмена if (capOK) { TClipboard *pCB=Clipboard(); // буфер обмена windows Graphics::TBitmap *Buffer=new Graphics::TBitmap; // сюда писать кадр будем DBImage1->Picture->LoadFromClipboardFormat(CF_BITMAP,pCB->GetAsHandle(CF_BITMAP),0); } }
//may be slow enough! BOOL CAviCap::_testInternalBuffers() { BOOL oldFlag = _fShow; //setup special callback _notify(lpNotify03,0); if(!capSetCallbackOnFrame(GetSafeHwnd(),(LPVOID)_timerFrameCallbackProc)) return (BOOL)(_internalBufCnt=0); _fShow = FALSE; //set the lowest resolution _pushResolution(); if(_biBitsCountSupported!=0&&_formats.GetSize()!=0) { DWORD biBitsCode; if(_biBitsCountSupported&BITS01) biBitsCode=BITS01; else if(_biBitsCountSupported&BITS04) biBitsCode=BITS04; else if(_biBitsCountSupported&BITS08) biBitsCode=BITS08; else if(_biBitsCountSupported&BITS16) biBitsCode=BITS16; else if(_biBitsCountSupported&BITS24) biBitsCode=BITS24; else biBitsCode=BITS24; LPBITMAPINFO bi=_mk_LPBITMAPINFO(biBitsCode,_smallFrame.cx, _smallFrame.cy); capSetVideoFormat(GetSafeHwnd(), bi, (WORD)_getBMIsize(bi)); _notify(lpNotify03,20); delete bi; } //some drivers needs to skip a few frames Sleep(100); _notify(lpNotify03,50); int i; for(i=0;i<MAX_VALID_BUFFERS_COUNT;i++) { _frameStarted = NOW(); capGrabFrame(GetSafeHwnd()); _notify(lpNotify03,60+i*10); if(_frameDelta>=MIN_FRAME_PERIOD) break; } //restore callback if(!_1FrameCallBackInstalled) capSetCallbackOnFrame(GetSafeHwnd(), (LPVOID)_defaultFrameCallbackProc); else capSetCallbackOnFrame(GetSafeHwnd(), (LPVOID)_1FrameCallbackProc); _InternalBufCnt= _internalBufCnt=i; TRACE("%d internal buffers found\n",_internalBufCnt); _popResolution(); _notify(lpNotify03,100); _fShow = oldFlag; return _internalBufCnt; }
// Notes: // 1. This routing may be slow enough // 2. This routing may cause of driver's notification, such as // "not enough memory..." or "...not for this videostandard..." etc // 3. There is no warranty for this format is really available :-( // 4. This is potentially DANGEROUS work! Some drivers can "freez"! BOOL CAviCap::_testFrameFormat(int x, int y) { LPBITMAPINFO bmpI; BOOL ret; if(!_bmpInfo) if(!_getFormat()) return FALSE; int biBitCount=(int)((LPBITMAPINFOHEADER)_bmpInfo)->biBitCount; switch(biBitCount) { case 1: biBitCount=BITS01; break; case 4: biBitCount=BITS04; break; case 8: biBitCount=BITS08; break; case 16:biBitCount=BITS16; break; case 24:biBitCount=BITS24; break; case 32:biBitCount=BITS32; break; default: return FALSE; } bmpI=_mk_LPBITMAPINFO(biBitCount,x,y); ret=capSetVideoFormat(GetSafeHwnd(), bmpI, (WORD)_getBMIsize(bmpI)); if(ret) //check one's more { #define _XX() (int)((LPBITMAPINFOHEADER)bmpI)->biWidth #define _YY() (int)((LPBITMAPINFOHEADER)bmpI)->biHeight int x=_XX(); int y=_YY(); capGetVideoFormat(GetSafeHwnd(), bmpI, (WORD)_getBMIsize(bmpI)); if(x!=_XX()||y!=_YY()) ret=FALSE; //Check is compressed if(ret) { _bufferSize = 0; //setup special callback for timing capSetCallbackOnFrame(GetSafeHwnd(),(LPVOID)_timerFrameCallbackProc); capGrabFrame(GetSafeHwnd()); if(!_1FrameCallBackInstalled) capSetCallbackOnFrame(GetSafeHwnd(), _defaultFrameCallbackProc); else capSetCallbackOnFrame(GetSafeHwnd(),(LPVOID)_1FrameCallbackProc); _cmprs_formats.Add((BOOL)(_bufferSize!=_calcBufferSize((LPBITMAPINFOHEADER)bmpI))); //end check } } delete bmpI; return ret; }
// // Note: according SDK LPVIDEOHEADER MUST(!) point to UNCOMPRESSED // video bufer (lpData). Can we trast or not? // Much better make sure... BOOL CAviCap::_IsImageCompressed() { if(!_bmpInfo) if(!_getFormat()) return FALSE; _bufferSize = 0; //setup special callback if(!capSetCallbackOnFrame(GetSafeHwnd(),(LPVOID)_timerFrameCallbackProc)) return FALSE; capGrabFrame(GetSafeHwnd()); if(!_1FrameCallBackInstalled) capSetCallbackOnFrame(GetSafeHwnd(), (LPVOID)_defaultFrameCallbackProc); else capSetCallbackOnFrame(GetSafeHwnd(),(LPVOID)_1FrameCallbackProc); //compare resulting buffer sizes return (_bufferSize!=_calcBufferSize((LPBITMAPINFOHEADER)_bmpInfo)); }