I see a few problems -
TheDelChop wrote:
GetObject(hSavedXYBitmap,sizeof(BITMAP),(LPSTR)(&bmp));
Irrelevent, but cast to a LPSTR?? No cast to a void pointer is necessary ;) Problems: Creating a BITMAPINFO the size of a BITMAPINFOHEADER. Using the planes value from the DDB when it HAS to be 1 in a DIB. bmiHeader.biSizeImage is calculated wrong - rows of pixel data in a DIB need to be DWORD aligned. You've provided no color table (16-colors) for your destination 4-bit DIB The resulting GetDIBits call should fail based on the above. Something like this maybe will get you closer:
...
int nNumColors = 1 << cClrBits;
LONG lBytesPerRow = (((bmp.bmWidth * (long)cClrBits + 31L) & (~31L)) / 8L);
BYTE* pBitmapBits;
LONG SizeOfBitmapInfo = sizeof(BITMAPINFO) + ((nNumColors - 1) * sizeof(RGBQUAD));
BITMAPINFO *pbmi = (PBITMAPINFO) LocalAlloc(LPTR, SizeOfBitmapInfo);
memset(pbmi, 0, SizeOfBitmapInfo);
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = bmp.bmWidth;
pbmi->bmiHeader.biHeight = bmp.bmHeight;
pbmi->bmiHeader.biPlanes = 1;
pbmi->bmiHeader.biBitCount = cClrBits;
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = lBytesPerRow * bmp.bmHeight;
//pbmi->bmiHeader.biXPelsPerMeter = 0;
//pbmi->bmiHeader.biYPelsPerMeter = 0;
//pbmi->bmiHeader.biClrUsed = 0;
//pbmi->bmiHeader.biClrImportant = 0;
// I forget if you need to do this before GetDIBits() :doh:
//// Initialize color table
//for (int i = 0; i < nNumColors; i++)
//{
// pbmi->bmiColors[i].rgbBlue = ;
// pbmi->bmiColors[i].rgbGreen = ;
// pbmi->bmiColors[i].rgbRed = ;
// pbmi->bmiColors[i].rgbReserved = 0;
//}
pBitmapInfoHeader = (PBITMAPINFOHEADER)pbmi;
lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED,pbmi->bmiHeader.biSizeImage);
test = ::GetDIBits(hdc, hSavedXYBitmap, 0, (WORD) pbmi->bmiHeader.biHeight, lpBits, pbmi, DIB_RGB_COLORS);
if (test == 0)
test = GetLastError();
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder