Jump to content
  • Advertisement
Sign in to follow this  
DarkRonin

Problems loading a Bitmap from memory

This topic is 2772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys, hopefully you can help me out as I have hit a brick wall and 'Dr. Google' isn't being of great help. :unsure:

I have a Win32 application in C++, where I have manually loaded a bitmap into memory. I know you can use LoadImage() etc.. But, I need it to be done this way for the (future) purpose of my application.

I have gotten to the point where my Bitmap is in memory but am having problems drawing it to the screen.

Here is my WM_PAINT code

case WM_PAINT:
{
// ***** THESE HAVE BEEN DECLARED GLOBALLY *****
// LPBITMAPINFO lpbi=NULL; // bitmap format info; used by GetDIBits
// LPVOID lpvBits=NULL; // pointer to bitmap bits array
// BITMAPFILEHEADER bmfh; // .bmp file header
// *********************************************

BITMAP hBitmap;
PAINTSTRUCT ps;

HDC hdc=BeginPaint(hWnd,&ps);

HDC hdcMem=CreateCompatibleDC(hdc);

hBitmap=CreateDIBSection(NULL,&lpbi,DIB_RGB_COLORS,(void**)&lpvBits,NULL,0);
SetDIBits(NULL,hBitmap,0,lpbi->bmiHeader.biHeight,lpbi->bmiHeader.biSizeImage,&lpbi,DIB_RGB_COLORS);

BitBlt(hdc,0,0,hBitmap.bmWidth,hBitmap.bmHeight,hdcMem,0,0,SRCCOPY);

SelectObject(hdcMem,hbmOld); // Not sure what to do here also...
DeleteDC(hdcMem);

EndPaint(hWnd,&ps);
}


But when I compile I get the following errors;

error C2664: 'CreateDIBSection' : cannot convert parameter 2 from 'LPBITMAPINFO *' to 'const BITMAPINFO *'
error C2664: 'SetDIBits' : cannot convert parameter 2 from 'BITMAP' to 'HBITMAP'

[size="1"]Any help would be absolutly awesome! B)

Share this post


Link to post
Share on other sites
Advertisement
The first error says that parameter 2 of CreateDIBSection should be a pointer, not a pointer-to-a-pointer. Change "&lpbi" to "lpbi".

Also, CreateDIBSection returns a HBITMAP, not a BITMAP, so change "BITMAP hBitmap;" to "HBITMAP hBitmap;"

Share this post


Link to post
Share on other sites
Thanks for your help.

Things are a little better but changing BITMAP to HBITMAP breaks the [color="#660066"]BitBlt[color="#666600"]() [color="#000000"]function.

error C2228: left of '.bmWidth' must have class/struct/union

Share this post


Link to post
Share on other sites
Try not to create all your stuff over and over every time you draw a frame, just do it once at creation and destroy it when you close.

The simplest way (and probably the fastest?) to draw a bitmap is to convert it to a 32 bit one after you load it and you can just do one memcpy per line.

Share this post


Link to post
Share on other sites
It looks like you may have another problem. Do you have lpbi = new BITMAPINFO somewhere? I.e., do you actually create the structure somewhere? GetDIBits needs a pointer to a structure to fill out, not just a pointer.

Normally one would declare BITMAPINFO bmi and pass &bmi for the required LPBITMAPINFO and BITMAPINFO* arguments in the various function calls.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!