Advertisement Jump to content
Sign in to follow this  
hungryhippo5000

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

Advertisement
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:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/loadimage.asp

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),
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );

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:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_912s.asp

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:

DeleteObject(BitmapHandle);

Hope this helped.

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.

GameDev.net 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!