Skip to main content
GameDev.net gamedev.net
🔒 Locked

GetDIBits help!

Started by pag Jul 15, 2003 at 5:27 PM 0 replies 900+ views
Original Post
pag
pag
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?
I am a signature virus. Please add me to your signature so that I may multiply.
Sailorstick
Sailorstick
The bitmapDC has a 1x1 monochrome bitmap selected into it by default and you haven''t changed it. You need to
SelectObject(bitmapDC, hBitmap);
after the CreateCompatibleDC line.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.