Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

omegasyphon

bitmap function

This topic is 6420 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

on the following bitmap function how would i make it so that it loads in an external file like bitmap.bmp instead of as a resource. are the changes i made correct?
  

int Load_Bitmap(char *name, int x, int y, LPDIRECTDRAWSURFACE7 dest_surface)
{
	HBITMAP hbitmap = NULL;
	BITMAP bmp;
	HDC image_dc, surface_dc;

// added LR_LOADFROMFILE

	// load bitmap resource

	if (!(hbitmap = (HBITMAP)LoadImage(hinstance, name,IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION)))
		return(FALSE);

	// create device context for image

	if (!(image_dc = CreateCompatibleDC(NULL)))
		return(FALSE);

	// select bitmap into the DC

	if (!(SelectObject(image_dc, hbitmap)))
		return(FALSE);

	// get surface device context

	if (FAILED(dest_surface->GetDC(&surface_dc)))
		return(FALSE);

	// get image dimensions

	GetObject(hbitmap, sizeof(BITMAP), &bmp);
    int dx = bmp.bmWidth;
    int dy = bmp.bmHeight;

	// copy image to surface

	if (!(BitBlt(surface_dc, x, y, dx, dy, image_dc, 0, 0, SRCCOPY)))
		return(FALSE);
	
	// get rid of all that stuff we used

	dest_surface->ReleaseDC(surface_dc);
	DeleteDC(image_dc);
	DeleteObject(hbitmap);

	return(TRUE);
}

  

Share this post


Link to post
Share on other sites
Advertisement
Yes... I also had this same question. For the answer I looked into the Microsoft DD7 header files "ddutil.h".

This is the snippet of code that you use to open a bitmap...
  
// load bitmap resource

if (!(hbitmap = (HBITMAP)
LoadImage(hinstance, name,IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION))) return(FALSE);


and here is the better snippet...


  
// Try to load the bitmap as a resource, if that fails, try it as a file

hbitmap = (HBITMAP) LoadImage( hInstance, name,
IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION );
if( hbitmap == NULL )
{
hbitmap = (HBITMAP) LoadImage( NULL, name,
IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION );
if( hbitmap == NULL )
{ MessageBox(hWnd," Could not load the specified bitmap from file or from the resource file. ", "DirectDraw Error: Surface Creation",MB_ICONERROR); return FALSE; }
}



First... this code tries to open the "name" string as a resource... but if the hbitmap == NULL then it tries to open it as an actual file.

I hoped this helped. I am new to the whole game programming thing.

Share this post


Link to post
Share on other sites

  • 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!