The following example shows how to capture a bitmap from video.
USHORT usUserParm = 0; BITMAPINFOHEADER2 *pBMPhdr; ULONG ulReturn; CHAR szInfoStr[500]; CHAR szTempStr[100]; ULONG ulFlags = 0; ulFlags = MCI_CONVERT; /**********************************************************/ /* Determine the length and characteristics of the buffer */ /**********************************************************/ memset ((PVOID)&mciImageParms, 0x00, sizeof (MCI_IMAGE_PARMS)); mciImageParms.hwndCallback = hwndNotify; mciImageParms.ulBufLen = 0; mciImageParms.pPelBuffer = 0; ulReturn = mciSendCommand(usDeviceID, MCI_GETIMAGEBUFFER, MCI_WAIT | ulFlags, (PVOID)&mciImageParms, usUserParm); /*************************************/ /* Allocate memory for the buffer */ /*************************************/ DosAllocMem (&mciImageParms.pPelBuffer, mciImageParms.ulBufLen, PAG_COMMIT | PAG_WRITE); /*********************************/ /* Get the data from the buffer */ /*********************************/ ulReturn = mciSendCommand(usDeviceID, MCI_GETIMAGEBUFFER, MCI_WAIT | ulFlags, (PVOID)&mciImageParms, usUserParm); pBMPhdr = (BITMAPINFOHEADER2 *)mciImageParms.pPelBuffer;
Note: The digital video device returns BITMAPFILEHEADER2 instead of BITMAPINFOHEADER2.
The following code illustrates how to capture an OS/2 bitmap from the hardware using the digital video device.
#define INCL_GPI #define INCL_GPIBITMAPS #include <os2.h> #include <pmbitmap.h> #define INCL_MMIO #define INCL_MMIO_CODEC #define INCL_MMIO_DOSIOPROC #include <os2me.h> #include <stdlib.h> /***************************************************************** * Name : BMPCaptureBitmap * * Function: Capture bitmap from hardware * ******************************************************************/ VOID BMPCaptureBitmap(PSWVRCB pCB, HWND hwnd) { MCI_IMAGE_PARMS mciImageParms; PCHAR pBuf=0L; HFILE hBMP; ULONG ulAction; ULONG cBytes; LONG rc; memset ((PVOID)&mciImageParms, 0x00, sizeof (MCI_IMAGE_PARMS)); /* prepare structures */ mciImageParms.pPelBuffer = 0L; mciImageParms.ulBufLen = 0L; mciImageParms.rect.xLeft = pCB->recopts[usIndex].usCapPosX; mciImageParms.rect.yBottom = pCB->recopts[usIndex].usCapPosY; mciImageParms.rect.xRight = pCB->recopts[usIndex].usCapSizeX + pCB->recopts[usIndex].usCapPosX; mciImageParms.rect.yTop = pCB->recopts[usIndex]usCapSizeY + pCB->recopts[usIndex].usCapPosY; mciImageParms.ulPelBufferWidth = pCB->recopts[usIndex].usMovieSizeX; mciImageParms.ulPelBufferHeight = pCB->recopts[usIndex].usMovieSizeY; rc = mciSendCommand( pCB->OutputMovie.usDeviceID, MCI_GETIMAGEBUFFER, MCI_WAIT | MCI_USE_HW_BUFFER | MCI_CONVERT, (ULONG)&mciImageParms, 0); rc = DosAllocMem ( (PPVOID) &pBuf, (ULONG) mciImageParms.ulBufLen, (ULONG) PAG_COMMIT | PAG_READ | PAG_WRITE); mciImageParms.pPelBuffer=(PVOID)pBuf; rc = mciSendCommand( pCB->OutputMovie.usDeviceID, MCI_GETIMAGEBUFFER, MCI_WAIT | MCI_USE_HW_BUFFER | MCI_CONVERT, (ULONG)&mciImageParms, 0); if (!rc) { /* getimage buffer is successful open file and write out bitmap */ rc = DosOpen ( (PSZ)pCB->szBitmapFilename, &hBMP, &ulAction, 0, FILE_NORMAL, FILE_CREATE, OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYWRITE, 0L); rc = DosWrite (hBMP, (PVOID)pBuf, mciImageParms.ulBufLen, &cBytes); rc = DosClose (hBMP); } /* free buffers */ DosFreeMem( pBuf ); }