Sign in to follow this  
geekalert

DIB colors not displaying correctly

Recommended Posts

Loading code:
HDC hDC = GetDC(hWnd);

bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
bmi.bmiHeader.biWidth = nWidth;
bmi.bmiHeader.biHeight = nHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = nBpp * 8;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = nWidth * nHeight * nBpp;

hDibDC = CreateCompatibleDC(hDC);
hDib = CreateDIBSection(hDibDC, &bmi, DIB_RGB_COLORS, &pDibBits, NULL, 0);

if(!pDibBits || !hDib)
{
	MessageBox(hWnd, "Error allocating DIB.", "Error", MB_OK | MB_ICONERROR);
	return 0;
}

SelectObject(hDibDC, hDib);
memcpy((unsigned char*) pDibBits, pPixels, nWidth * nHeight * nBpp);

ReleaseDC(hWnd, hDC);

Drawing Code:
PAINTSTRUCT ps;
BeginPaint(hWnd, &ps);

HDC hDC = GetDC(hWnd);

if(pPixels && hDibDC)
{
	BitBlt(hDC, 0, 0, nWidth, nHeight, hDibDC, 0, 0, SRCCOPY);
}

ReleaseDC(hWnd, hDC);
EndPaint(hWnd, &ps);

The pic on the left is how it looks. The pic on the rite is how it SHOULD look. It looks like the RED values of my color array are not being copied correctly. Can anyone help? Some more background info: pPixels is an array of unsigned chars. it's formate is {red, green, blue, red, green, blue} at 24 bits per pixel pDibBits is void, but is allocated as nWidth * nHeight * nBpp, and nBpp is (3 bytes) SO it SHOULD act as an array of unsigned chars.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this