Archived

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

ztn

Loading Bitmaps without reasources?

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;
PathAndFilenameWithExtension:String;
BitmapWidth:Integer;
BitmapHeight:Integer;

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

BitmapHandle:=LoadImage(0,pchar(PathAndFilenameWithExtension),IMAGE_BITMAP,BitmapWidth,BitmapHeight,LR_LOADFROMFILE);

//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;
BitmapDC;
WindowHandle:THandle;

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

DC:=GetDC(WindowHandle);

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

BitmapDC:=CreateCompatibleDC(DC);

//Next select the bitmap into the BitmapDC.

SelectObject(BitmapDC,BitmapHandle);

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

BitBlt(DC,XDest,YDest,BitmapWidth,BitmapHeight,BitmapDC,BitmapWidth,BitmapHeight,SRCCOPY);

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

If you have any questions, feel free to ask,

Thijs Jellema

to_thijs@hotmail.com

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?
zTn


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:


//
BITMAP bm;
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);

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




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

Share this post


Link to post
Share on other sites