0

I posted this question in the regular C++ forum and havn't gotten any answers.
hoping I will have better luck here, here was the question:
http://www.daniweb.com/forums/thread160790.html

I need to load a bitmap from file, and get an array of bits that I cain use.
I have used CreateDIBSection() to create a backbuffer for the screen.
my array is
UINT *pBits;
I need to load the bitmap so that I can go like this:
pBits[bit] = pLoadedBitmap[bit];

I am trying to get it to work like this right now:

HBITMAP hTexture;
BYTE *pBitData;
BITMAPINFO bmInfo;
BITMAP gBitmap;

hTexture = (HBITMAP)LoadImage(0, "texture.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);


GetObject(hTexture, sizeof(BITMAP), (LPVOID)&gBitmap);

bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmInfo.bmiHeader.biWidth = gBitmap.bmWidth;
bmInfo.bmiHeader.biHeight = gBitmap.bmHeight;
bmInfo.bmiHeader.biPlanes = 1;
bmInfo.bmiHeader.biBitCount = gBitmap.bmPlanes * gBitmap.bmBitsPixel;
bmInfo.bmiHeader.biCompression = BI_RGB;
bmInfo.bmiHeader.biSizeImage = gBitmap.bmWidth * gBitmap.bmHeight;
bmInfo.bmiHeader.biXPelsPerMeter = 0;
bmInfo.bmiHeader.biYPelsPerMeter = 0;
bmInfo.bmiHeader.biClrUsed = 0;
bmInfo.bmiHeader.biClrImportant = 0;

pBitData = new BYTE[bmInfo.bmiHeader.biSizeImage]; 
GetDIBits(0, hTexture, 0, 0, pBitData, &bmInfo, DIB_RGB_COLORS);

//when I do somdething like this:
for(int n = 0; n < bmInfo.bmiHeader.biSizeImage; n++
    pBits[n] = pBitData[n];

//all I get is a mess of blue pixels that seems to be random.

can anyone help?

1
Contributor
2
Replies
3
Views
8 Years
Discussion Span
Last Post by VBNick
0

GetDIBits returns 0 meaning that it has failed =/ anyone know why that might be?

0

fixed it...
GetDIBits wouldnt work without also attaching the bitmap to an HDC
first.
also, I used this struct, with sizeof(struct) = 4
which is very convenient because I will add alpha blending later.
struct BGR
{
BYTE B;
BYTE G;
BYTE R;
BYTE p
;typedef BGR *pBGR;
pBGR pBitData = new BGR[gBitmap.bmWidth * 4 * gBitmap.bmHeight];

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.