hi, I have used LoadImage() to load a bitmap as HBITMAP. If I use SelectObject() to attach it to an HDC, and then BitBlt() it to the screen, that works fine. I need an array that would be compatible with the one produced by CreateDIBSection(). I have tried GetBitmapBits(), and also GetDIBits() I was able to get it to compile, but ended up with an error when I tried to read from the array. I created a breakpoint and tried to look at the array, and it says "0x000000" when I hover the mouse over it.

can anyone help me out?

if it helps, here is the code that I am using to produce the array that needs to be copied to, and how I am trying to load the bitmap:

//creatingthe DIB section for the screen buffer
UINT *pBits;
BITMAPINFO bmi;

bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = SCREENWIDTH;
bmi.bmiHeader.biHeight = -SCREENHEIGHT;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB; 
bmi.bmiHeader.biSizeImage = 0;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;	

hBitmap = CreateDIBSection(NULL,(BITMAPINFO*)&bmi, DIB_RGB_COLORS, (VOID**)&pBits, NULL, 0);

pBits[x] = color; // I want to get the colors from the loaded image
pBits[x] = ect;
pBits[x] = ect...;

//then, set it to the window's dc on WM_PAINT
SetDIBitsToDevice(pstruct.hdc,0,0,SCREENWIDTH, SCREENHEIGHT,0,0,0,SCREENHEIGHT,pBits,(BITMAPINFO *)&bmi,DIB_RGB_COLORS);

//this is how I am loading the bitmap
HBITMAP hBitmap;
hTexture = (HBITMAP)LoadImage(0, "texture.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);

//now I needto get the array of bits somehow:
LPBITMAPINFO bmInfo;
int result = 0;

result = GetDIBits(NULL, hTexture, 0, 100, texBits, bmInfo, DIB_RGB_COLORS);
if(result == KABOOM)
{
   CryToMembersOfDaniWeb(); // ehehe =)
}

if I can get the GetDIBits to work right, I'm all set.
thanks again.

ok, I am getting something now...but its just a bunch of blue jiberish =/
I am using this code:

BYTE* pBitData;
BITMAPINFO bmInfo;
BITMAP gBitmap;

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 = 24;
    bmInfo.bmiHeader.biCompression = BI_RGB;
    bmInfo.bmiHeader.biSizeImage = 0;
    bmInfo.bmiHeader.biXPelsPerMeter = 0;
    bmInfo.bmiHeader.biYPelsPerMeter = 0;
    bmInfo.bmiHeader.biClrUsed = 0;
    bmInfo.bmiHeader.biClrImportant = 0;

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

looping through the elements in pBitData and putting them on the screen only produced a bunch of dark blue seemingly random pixels =/
and I cant figure out how to determine the size of pBitData
also changing BYTE to UINT like the first array produced a different combination of randomly coloured pixels...lol =(

Edited 3 Years Ago by Reverend Jim: Fixed formatting

iif I opened a bitmap file with fopen, and got the bits that way, would that be compatible if I wanted to copy directly to the array I specified above? UINT pBits[x] = pBitsFromFile[x]?
I havnt been able to get a bitmap to open right yet..wondering if its worth trying

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 question has already been answered. Start a new discussion instead.