Article ID: 126575
Article Last Modified on 3/16/2004
SetDIBits
SetDIBitsToDevice
CreateDIBitmap
StretchDIBits
/* Macro to determine the bytes in a DWORD aligned DIB scanline */
#define BYTESPERLINE(Width, BPP) ((WORD)((((DWORD)(Width) *
(DWORD)(BPP) + 31) >> 5)) << 2)
int NewStretchDIBits(
HDC hdc, // handle of device context
int XDest, // x-coordinate of upper-left corner of dest. rect.
int YDest, // y-coordinate of upper-left corner of dest. rect.
int nDestWidth, // width of destination rectangle
int nDestHeight, // height of destination rectangle
int XSrc, // x-coordinate of upper-left corner of source rect.
int YSrc, // y-coordinate of upper-left corner of source rect.
int nSrcWidth, // width of source rectangle
int nSrcHeight, // height of source rectangle
VOID *lpBits, // address of bitmap bits
BITMAPINFO *lpBitsInfo, // address of bitmap data
UINT iUsage, // usage
DWORD dwRop // raster operation code
)
{
BITMAPINFOHEADER bmiTemp;
float fDestYDelta;
LPBYTE lpNewBits;
int i;
// Check for NULL pointers and return error
if (lpBits == NULL) return 0;
if (lpBitsInfo == NULL) return 0;
// Get increment value for Y axis of destination
fDestYDelta = (float)nDestHeight / (float)nSrcHeight;
// Make backup copy of BITMAPINFOHEADER
bmiTemp = lpBitsInfo->bmiHeader;
// Adjust image sizes for one scan line
lpBitsInfo->bmiHeader.biSizeImage =
BYTESPERLINE(lpBitsInfo->bmiHeader.biWidth,
lpBitsInfo->bmiHeader.biBitCount);
lpBitsInfo->bmiHeader.biHeight = 1;
// Initialize pointer to the image data
lpNewBits = (LPBYTE)lpBits;
// Do the stretching
for (i = 0; i < nSrcHeight; i++)
if (!StretchDIBits(hdc,
XDest, YDest + (int)floor(fDestYDelta * (nSrcHeight - (i+1))),
nDestWidth, (int)ceil(fDestYDelta),
XSrc, 0,
nSrcWidth, 1,
lpNewBits, lpBitsInfo,
iUsage, SRCCOPY))
break; // Error!
else
// Increment image pointer by one scan line
lpNewBits += lpBitsInfo->bmiHeader.biSizeImage;
// Restore BITMAPINFOHEADER
lpBitsInfo->bmiHeader = bmiTemp;
return(i);
}
Additional query words: 1.15 1.20 1.10
Keywords: KB126575