Original Post
I'm trying to make a function which takes a bitmap and replaces every src color to des color. However I am having trouble retrieveing the bitmaps bits. My code looks like this so far:
BOOL ReplaceColor(HBITMAP hBitmap, COLORREF clSrcColor, COLORREF clDesColor)
{
HDC bitmapDC;
BITMAP bitmap;
unsigned char* bitmapBits; bitmapDC = CreateCompatibleDC(NULL); GetObject(hBitmap, sizeof(BITMAP), &bitmap);
BITMAPINFO bitmapInfo; ZeroMemory(&bitmapInfo.bmiHeader, sizeof(BITMAPINFOHEADER)); bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bitmapInfo.bmiHeader.biWidth = bitmap.bmWidth; bitmapInfo.bmiHeader.biHeight = bitmap.bmHeight; bitmapInfo.bmiHeader.biPlanes = 1; bitmapInfo.bmiHeader.biBitCount = 8; bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmapBits = new unsigned char[bitmap.bmWidth*bitmap.bmHeight]; int scanLines = GetDIBits(bitmapDC, hBitmap, 0, bitmap.bmHeight, bitmapBits, &bitmapInfo, DIB_RGB_COLORS); if(scanLines == 0) return FALSE;
return TRUE; }And it fails, as no scanlines are read. And the problem is not what I fill in the bmiHeader as I know the bitmap is uncompressed and is 8bits per pixel... Any ideas?