Advertisement Jump to content
Sign in to follow this  

Loading BMP from resource

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

Well, I dont know about directX9, but this may help.
Windows has a nifty LoadImage function that can either load an image from file or a resource:

First off, you need to create 2 variables, a bitmap object, and a bitmap handle:
HBITMAP BitmapHandle;
BITMAP Bitmap;

Next, you get the handle of the bitmap using the load image function. A link to the online MSDN page on this function is posted below:

HANDLE LoadImage( HINSTANCE hinst, //The Window Handle
LPCTSTR lpszName, //The Name of the Bitmap (or resource ID)
UINT uType, //The Type of Image
int cxDesired, //The Desired Width (0 for all)
int cyDesired, //The Desired Height (0 for all)
UINT fuLoad //Loading Flags

The call to the function would look something like this:

BitmapHandle = (HBITMAP)LoadImage( HInstance, MAKEINTRESOURCE(ResourceID),

Where HInstance is the instance of the window and ResourceID is the ID of the resource.

Next, you have to get the actual bitmap from the handle, by calling the GetObject Function:

int GetObject(
HGDIOBJ hgdiobj, // handle to graphics object
int cbBuffer, // size of buffer for object information
LPVOID lpvObject // buffer for object information

The call looks like this:
GetObject(BitmapHandle, sizeof(Bitmap), &Bitmap);

As for actually adding the bitmap to the surface, I can't really help you there. In DX7, you create a compatible DC and just Blt the bitmap to the surface. However, in DX9, you might have to use it as a texture.

Make sure to delete the object when you are done with it:


Hope this helped.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!