PDA

View Full Version : GDI use in Filter SDK?



Unregistered
April 14, 2003, 13:39:29
Hi,

can i use GDI functions with the Filter SDK, for example to write results directly onto the video stream?

Marc Cymontkowski
April 14, 2003, 13:48:59
Yes, you can use GDI functions with the Filter SDK. Look at the Measurement sample of the development kit to see how it is done.

The following TransformSample function shows how to use GDI to draw "Hello World" into the upper left corner of the video stream.



STDAPI TransformSample( BYTE* pInBuffer,
BYTE* pOutBuffer,
int iWidth,
int iHeight,
int iBytePerPixel,
int iPitch,
void* pSavePointer,
PVOID pIOInBuffer,
INT iIOInBufferSize,
PVOID pIOOutBuffer,
INT iIOOutBufferSize)
{
//
// First we create a DC that we can use with GDI
//
HDC hDC = CreateCompatibleDC(0);

//
// Create a DIB bitmap
//
// Initialize a bitmap info structure
BITMAPINFO bmInfo = {0};
bmInfo.bmiHeader.biBitCount = (short)iBytePerPixel * 8;
bmInfo.bmiHeader.biCompression = BI_RGB;
bmInfo.bmiHeader.biPlanes = 1;
bmInfo.bmiHeader.biSize = sizeof(bmInfo.bmiHeader);
bmInfo.bmiHeader.biWidth = iWidth;
bmInfo.bmiHeader.biHeight = iHeight;
bmInfo.bmiHeader.biSizeImage = iHeight * iPitch;

// Create a DIB bitmap from our bitmap info structure
BYTE *pbyBits;
HBITMAP hBitmap = CreateDIBSection( hDC, &bmInfo, DIB_RGB_COLORS, (void**)&pbyBits, 0, 0 );
//
// Copy the input buffer into our bitmap
//

CopyMemory( pbyBits, pInBuffer, iHeight * iPitch );

//
// Select our bitmap into the dc
//
HDC hOldBitmap = (HDC)SelectObject( hDC, hBitmap );

// Use GDI Functions

SetTextColor( hDC, 0xff0000 );
TextOut(hDC, 10, 10, "Hello World", strlen("Hello World"));

//
// Copy the processed bitmap data to the output buffer
//

CopyMemory( pOutBuffer, pbyBits, iHeight * iPitch);
//
// Set the old bitmap
//

SelectObject( hDC, hOldBitmap );

//
// Clean up!
//

// Bitmap
DeleteObject( hBitmap );

// DIB-DC
DeleteDC( hDC );


return S_OK;
}



Best regards

Marc Cymontkowski