Jump to content
  • Advertisement
Sign in to follow this  

DIB colors not displaying correctly

This topic is 4433 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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:
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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!