LoadImage() to bit array

Please support our Game Development advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2008
Posts: 84
Reputation: VBNick is an unknown quantity at this point 
Solved Threads: 1
VBNick VBNick is offline Offline
Junior Poster in Training

LoadImage() to bit array

 
0
  #1
Dec 5th, 2008
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?
Last edited by VBNick; Dec 5th, 2008 at 4:52 pm. Reason: forgot to post the code
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 84
Reputation: VBNick is an unknown quantity at this point 
Solved Threads: 1
VBNick VBNick is offline Offline
Junior Poster in Training

Re: LoadImage() to bit array

 
0
  #2
Dec 5th, 2008
GetDIBits returns 0 meaning that it has failed =/ anyone know why that might be?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 84
Reputation: VBNick is an unknown quantity at this point 
Solved Threads: 1
VBNick VBNick is offline Offline
Junior Poster in Training

Re: LoadImage() to bit array

 
0
  #3
Dec 5th, 2008
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];
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Game Development Forum


Views: 810 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Game Development
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC