Jump to content
  • Advertisement


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


Loading Bitmaps without reasources?

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

I''m learning to load bitmaps into my apps using Win32 API. The methods i''ve found use reasource files, which seems stupid becuase they keep the image data in the executible (which is silly for big images) and thusly you have to recompile evey time an image is updated. How do you write loading code that reads in the image from the file during run time? thanks, zTn PS no, i''m not too worried about performance...

Share this post

Link to post
Share on other sites
Hello zTn!

To Load bitmaps without using a recsource with standard win32 API functions is "very simple", at first it may look diffucult, but once you know it, you know it
I make my programs with Delphi (pascal), so the following code is in pascal, translating to c++ if you want to do that, ain''t that difficult.

But here''s the code:

//Use the function loadimage, this will return a handle, that
//is an identifier, something like a pointer, for that
//bitmap from windows.

var BitmapHandle:hBitmap;

//For example: PathAndFilenameWithExtension:=''Bitmap.bmp'';
// BitmapWidth:=100;
// BitmapHeight:=75;


//Next load the bitmap into the devicecontext (if you don''t
//know what that is mail me, or see documentation on GameDev).

//I assume you have the handle of your window stored in the
//variable WindowHandle.

var DC:hDC;

//A handle from the DC (Device Context) can be retrieved with:


//Now you need to create a DC for the bitmap.


//Next select the bitmap into the BitmapDC.


//And blit the bitmap to the "canvas" of the window.


//That''s it, note that this is not transparent bitmap blitting.

If you have any questions, feel free to ask,

Thijs Jellema


Share this post

Link to post
Share on other sites
Hey! This didn''t work either! As soon as i removed the reasource file from the build, the run fails with

"The specified image file did not contain a reasource section."

There must be a way to load the file at runtime! Anybody?

PS Working in MS Visual Studio 6

Share this post

Link to post
Share on other sites
I think that is exactly what i am using:

HBITMAP hbmBall;
HDC hdcMemory, hdcWindow;

//Load Image File
hbmBall = LoadBitmap(phInstance, "Intro.bmp");
if(!hbmBall)Process_Error("void zwindow::InitIntroImage", "Intro.bmp");

//Aquire Window Content & Memory space
hdcWindow = GetDC(hwnd);
hdcMemory = CreateCompatibleDC(hdcWindow);
SelectObject(hdcMemory, hbmBall);
GetObject(hbmBall, sizeof(bm), &bm);

//Draw Image
BitBlt(hdcWindow, 0, 0, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCCOPY);

if (!ReleaseDC(hwnd, hdcWindow)) Process_Error("zDescWin::Draw() ReleaseDC() Failure");

Is there some setting in VC that i''m not aware of maybe?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!