000 從擷取圖片

Post date: 2015/5/12 上午 06:46:29

int SnapshotBitmap( IBasicVideo * BasicVideo, const char * OutFile) { if( BasicVideo ) { long BitmapSize = 0; //首先获得图像大小 if( SUCCEEDED( BasicVideo->GetCurrentImage( &BitmapSize,0))) { BOOL PassImage = FALSE; unsigned char * Buffer = new unsigned char[BitmapSize]; //获取图像帧数据 if( SUCCEEDED( BasicVideo->GetCurrentImage(&BitmapSize,(long *)Buffer))) { // Create a file to hold the bitmap HANDLE hf = CreateFileA(OutFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, NULL, NULL ); if( hf == INVALID_HANDLE_VALUE ) { return 0; } // get width and height long height, width; if(pIBasicVideo) { pIBasicVideo->get_VideoHeight(&height); pIBasicVideo->get_VideoWidth(&width); } // Write out the file header // BITMAPFILEHEADER bfh; memset( &bfh, 0, sizeof( bfh ) ); bfh.bfType = 'MB'; bfh.bfSize = sizeof( bfh ) + BitmapSize + sizeof( BITMAPINFOHEADER ); bfh.bfOffBits = sizeof( BITMAPINFOHEADER ) + sizeof( BITMAPFILEHEADER ); // Write the bitmap format // BITMAPINFOHEADER bih; memset( &bih, 0, sizeof( bih ) ); bih.biSize = sizeof( bih ); bih.biWidth = width; bih.biHeight = height; bih.biPlanes = 1; bih.biBitCount = 32; DWORD Written = 0; WriteFile( hf, &bfh, sizeof( bfh ), &Written, NULL ); Written = 0; WriteFile( hf, &bih, sizeof( bih ), &Written, NULL ); Written = 0; WriteFile( hf, Buffer, BitmapSize, &Written, NULL ); CloseHandle( hf ); PassImage = TRUE; } delete [] Buffer; } } return 0; }