NVM Figured it out.
NVM Figured it out.
Last edited by abachler; 03-21-2009 at 05:03 PM.
GAH, no I didn't. I tried this code, which came right form a tutorial, and it doesnt work either -
I hate losing source code, otherwise id copy and past my already working code from other projects.Code:case WM_PAINT: hdc = BeginPaint(hwnd, &ps); hdcMem = CreateCompatibleDC(hdc); g_hbmBall = CreateBitmap(640 , 480 , 1 , 24 , Display); hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmBall); GetObject(g_hbmBall, sizeof(bm), &bm); BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, hbmOld); DeleteObject(g_hbmBall); DeleteDC(hdcMem); EndPaint(hwnd, &ps); return 0;
Try CreateCompatibleBitmap()
but...
Your code will just copy a blank image to the screen
I think you want to create the mem DC at start,
load an image into it (LoadImage()).
use this mem DC to copy the image when a paint is required
and only release these on close.
I also suggest 'clearing' the current screen with something like FillRect()
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
I already have the image data in the BYTE* Display buffer, LoadImage is irrelevant, I'm not trying to display a bitmap from a file. The image in Display is updated frequently, so I need to recreate the bitmap each time to make sure it displays the latest frame.
So basically I have a RAW RGB 24 bits per pixel image, in Display[], and I need to get that image into a bitmap object, and GDI isn't being very cooperative.
I am getting an image, but it is mangled, its more than just a simple 32/24 bit incompatibility because if I upconvert the image, it is still mangled.
Current code used for the image -
Code:case WM_PAINT: hdc = BeginPaint(hwnd, &ps); //hdc = GetDC(hwnd); hdcMem = CreateCompatibleDC(NULL); //bmi.bmiColors = NULL; bmi.bmiHeader.biWidth = 640; bmi.bmiHeader.biHeight = 480; bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biSize = 1228800; bmi.bmiHeader.biSizeImage = 0; bmi.bmiHeader.biClrImportant = 0; bmi.bmiHeader.biClrUsed = 0; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biXPelsPerMeter = 1200; bmi.bmiHeader.biYPelsPerMeter = 1200; //g_hbmDisplay = CreateBitmap(640 , 480 , 1 , 24 , Display); //g_hbmDisplay = CreateCompatibleBitmap(hdc , 640 , 480); g_hbmDisplay = CreateDIBitmap(hdc , &bmi.bmiHeader , 0 , Display , &bmi , DIB_RGB_COLORS); GetObjectA(g_hbmDisplay, sizeof(bm), &bm); //GetDIBits(hdc , g_hbmDisplay , 0 , 480 , NULL , &bmi , DIB_RGB_COLORS); if(g_hbmDisplay == NULL){ Beep(1000 , 50); //g_hbmDisplay = (HBITMAP)LoadImageA(hThis,"640x480.bmp",IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); //GetObjectA(g_hbmDisplay, sizeof(bm), &bm); //g_hbmDisplay = CreateDIBitmap(hdcMem , &bm , CBM_INIT , Display , &bm , DIB_RGB_COLORS); } //hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmDisplay); //GetObject(g_hbmDisplay, sizeof(bm), &bm); SetBitmapBits(g_hbmDisplay , 921600 , Display); //SetDIBits(hdcMem , g_hbmDisplay , 0 , 480 , Display , &bmi , DIB_RGB_COLORS); SelectObject(hdcMem , g_hbmDisplay); BitBlt(hdc, 0, 0, 640, 480, hdcMem, 0, 0, SRCCOPY); //SelectObject(hdcMem, hbmOld); DeleteObject(g_hbmDisplay); DeleteDC(hdcMem); //DeleteDC(hdc) EndPaint(hwnd, &ps); return 0;
Last edited by abachler; 03-22-2009 at 05:55 AM.
Hmm... bmiHeader.biSize refers to the size of the BITMAPINFOHEADER struct... are you sure it's 1.2 MB? I thought it was more like 40 bytes.
I think bmiHeader.biSizeImage is where that particular number should go, although I don't think you need to define it.
You may as well ignore the biXPelsPerMeter and biYPelsPerMeter params, I think they're only relevant for printer DCs.
In GDI nomenclature DIB dimensions are usually expressed with negative height (e.g. -480). This is a throwback to the OS/2 days.
I'd forget about the SetBitmapBits call, stick with SetDIBits instead and the changes above.
Solved it, turns out it WAS a 32/24 conversion issue, I just messed up the conversion function.
Last edited by abachler; 03-22-2009 at 12:07 PM.