Sign in to follow this  
Grantyt3

Can You Pack Images Into an EXE?

Recommended Posts

Yes
You can put them in the executable resources.

Note: assumed you are using C++:
resource.h

#define ID_BITMAP_RESOURCE 1001





resource.rc

ID_BITMAP_RESOURCE BITMAP DISCARDABLE "bitmap.bmp"





*.cpp

HBITMAP hBMP;
BITMAP BMP;

hBMP = (HBITMAP)LoadImage(GetModuleHandle(null), MAKEINTRESOURCE(ID_BITMAP_RESOURCE), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);

if(!hBMP)
return false;

// You can cut this out if you want to use the bitmap for Win32 stuff since you only need the hBMP
GetObject(hBMP, sizeof(BITMAP), &BMP);

// Remember to free these resources after ther're not needed anymore






That code should load a resource bitmap into BMP, take a look at the BITMAP structure for more info

[edit]
Found these usefull links:
http://www.emmestech.com/colin_peters_tutorial/resources/bitmap.html
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_2h6a.asp
[edit]

Hope that helps!

[Edited by - RaptorZero on April 22, 2006 9:41:13 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Grantyt3
Is it possible to pack the images used in a program into the executable file at compile-time so that all the needed files are contained in the exe?
An easy and portable way is to write a small script which converts an image file's contents into a string like this:

static const unsigned char* myImage="\x03\x53\x2A\x5F...";

And copy this line into your program. Then pass myImage to whatever image loading function you have. I'm not 100% sure on this, but I think it'll be equally fast and essentially use equal amount of memory as any other solution, on current OSs (the array will be loaded from disk to memory only once it is accessed, and if you run out of memory the pages with the image-array will just be dropped--it's already in the disk anyway if needed again later).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Don't over do it though. Resources increase the amount of time it takes for your program to load, and they also increase the memory footprint of your exe file, once loaded.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this