   Creating a bitmap from raw DWORD aligned data
  I start off with an array of raw RGB data, and I have a conversion function that makes it into BMP data. So it is DWORD aligned as the prototypes on msdn say.  But, when I use CreateBitmap, all I get is a monochome bitmap with alternating lines, and when I use CreateDIBSection, everything turns black.All I need to be able to do is to get the raw data into an Hbitmap somehow so I can display it.Here is the code I have:Again, this use of the CreateDIBSection just leaves me with an HBitmap that is completely black.BYTE * bimage = ConvertRGBToBMPBuffer ( image, 32, numtiles*32, &s);BITMAPINFOHEADER bmih = { sizeof (BITMAPINFOHEADER) };bmih.biPlanes = 1;bmih.biBitCount = 32;bmih.biCompression = BI_RGB;bmih.biWidth = 32;bmih.biHeight = 32;HBITMAP hLoad = CreateDIBSection (NULL, (BITMAPINFO *)&bmih, DIB_RGB_COLORS, (void **)&bimage, NULL, 0);Any help would be greatly appreciated!!!-Shane 
  This is a working example i did some time agoBITMAPINFO bi;bi.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );bi.bmiHeader.biWidth = imgWidth;bi.bmiHeader.biHeight = imgHeight;bi.bmiHeader.biPlanes = 1;bi.bmiHeader.biBitCount = 24;bi.bmiHeader.biCompression = BI_RGB;BYTE *newBuffer;HBITMAP hBmp = CreateDIBSection( hDc, &bi, DIB_RGB_COLORS, (void **)&newBuffer, I''m not sure ifBITMAPINFOHEADER bmih = { sizeof (BITMAPINFOHEADER) };is right in that way, but anyway you''re missingbi.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );Hope that helps-Mat ;  I just threw that stuff in there, but I get the same thing.  The bitmap is still only black.Any idea what could be wrong?Thanks! ;  2 things to try:1. check if the returned hbmp is ok and the GetLastError if is not.2. check yout pixels, can''t recall exactly if is ARGB or 0RGB or BGRA or what, just set the middle bytes to 255 to be 100% sure the rest is ok == 0x00ffff00-Mat;  Okay, the hbmp is okay except for the fact that it is all black.    It doesn''t return NULL if that''s what you mean.  But I did do the GetLastError(), and it returned an error code 8.  I looked it up and found that it is "Not enough storage available to process this command."  How could that be?  And also, what could I do to fix that?Right now, the pixels are set at BGR0 I think.  How would I find out what the function needs in order to work?Thanks!-Shane ;  Anyone have any ideas? ;  Hey sorry for the delay, gamedev was down and i was busy, took me a little bit until i realized what's wrong.In your call to CreateDIBSection the parameter (void **)&bimage is an OUT parameter not an IN parameter.From MSDN:ppvBits [out] Pointer to a variable that receives a pointer to the location of the DIB bit values. It means you have to change a bit your program since you're doing BYTE * bimage = ConvertRGBToBMPBuffer ( image, 32, numtiles*32, &s);I guess from here the solution is just trivial, just a BYTE *buff and a memcpy after CreateDIBSection That should do the trick-MatEDIT: PS: guess what was the next line from the sample i posted?memcpy( newBuffer, image, imageSize );   [edited by - matias suarez on February 15, 2004 8:12:52 PM];  Okay, I'm not sure what's goin on now.  I threw that stuff in - passed a new BYTE pointer into the CreateDIBSection function, then added memcpy( buffer, bimage, s );When I convert it to bitmap data, and save it to a file, it saves perfectly.  But, after I do the memcpy, I get a strange black and white tile.  This happens I convert it to BMP data, or leave it as RGB data.  I can't come up with any reason as to why this wouldn't work.  I'm probably missing something stupid.If you have any more ideas, let me know.Thanks!-ShaneEDIT: I stepped through some of the buffer, and the RGB data in there looks exactly right - for example, the first few rows match the pixel data exactly from what I checked in a bitmap editor.  My question is this: I don't understand how the data gets into the HBitmap hLoad.  I think that has to be the problem, because the data looks fine in the array. [edited by - shane1985 on February 15, 2004 10:29:05 PM];  Sorry but I don''t fully understand the question, i supose you have now something like:BYTE * bimage = ConvertRGBToBMPBuffer ( image, 32, numtiles*32, &s);BYTE *buffer;BITMAPINFOHEADER bmih = { sizeof (BITMAPINFOHEADER) };bmih.biPlanes = 1;bmih.biBitCount = 32;bmih.biCompression = BI_RGB;bmih.biWidth = 32;bmih.biHeight = 32;HBITMAP hLoad = CreateDIBSection (NULL, (BITMAPINFO *)&bmih, DIB_RGB_COLORS, (void **)&buffer, NULL, 0);memcpy( buffer, bimage, s );After that if i follow your post you checked that values in bimage/buffer sounds to be reasonable?As for the pixel format, i checked it and is bgr0 so be sure you''re not passing 0rgb or rgb0 as it is a common mistake But then i get lost with this...When I convert it to bitmap data, and save it to a file, it saves perfectly. But, after I do the memcpy, I get a strange black and white tile. This happens I convert it to BMP data, or leave it as RGB data. What do you mean by save it to a file? the hbitmap? the array of pixels?As for your question:  I don''t understand how the data gets into the HBitmap hLoadIs fairly simple: when you call HBITMAP hLoad = CreateDIBSection (NULL, (BITMAPINFO *)&bmih, DIB_RGB_COLORS, (void **)&buffer, NULL, 0);buffer returns with the address where the pixel info ''is/will be'' stored but is not there yet as it is now uninitialized data, so when you do a memcpy( buffer, yourdata, yourdatasize ) you are copying your data into the pointer returned by CreateDIBSection.If your pixel format (coming from ConvertRGBToBMPBuffer) is exactly an array of bgr0 values then you may have a problem when you display it, anyway i found this (that i never did before so is new for me too) at the end of the api:Windows NT/ 2000: You need to guarantee that the GDI subsystem has completed any drawing to a bitmap created by CreateDIBSection before you draw to the bitmap yourself. Access to the bitmap must be synchronized. Do this by calling the GdiFlush function. This applies to any use of the pointer to the bitmap''s bit values, including passing the pointer in calls to functions such as SetDIBits. Hope it helps-Mat;  Yeah, you have the first part right - and it is in BGR0 - but as a side note, I get the same results when it is RGB if that means anything (I was desperate).  As for the next part - I am saving the array of pixels in BGR0 format to a bitmap file before doing anything.  So, I know the array is fine before I touch it in this section.  Maybe the error occurs afterwards:Here''s what I''m doing after that part is finished.HDC hdc, bmpdc;hdc = GetDC(hwnd);bmpdc = CreateCompatibleDC(hdc);SelectObject(bmpdc, hLoad);BitBlt(hdc, 64,64, 32, 32, bmpdc, 0, 0, SRCCOPY);I tried the GdiFlush in there before the drawing, but that didn''t solve the problem.But yes, it is exactly an array of BGR0 values.If you have any more ideas, let me know.Thanks!-Shane