Bitmap loading without resource files & other questions
I''m currently facing a problem. I''ve writting a program in which I need to load 12 .BMP files. Loading them is OK if I manually call the LoadImage function 12 times. I was just wondering if there was another way to do this, so I tried a resource file.
I think it loaded properly in the resource file(I''m using lcc-win32 which doesn''t support viewing bitmaps in the resource editor) and it compiles alright. But I can''t run the exe file. Windows says that the *.exe file is corrupted and when I look at the file size, the *.exe file is now bigger than 4MB.
It seems that the compiler coded all the bitmaps into the *.exe file (is this normal when using a resource file ?). When I removed the bitmaps from the resource file, everything went back to normal.
So, now I''m trying to woro out a way to load images without using resource files. The reason I tried to use resource files is because I "could" load the bitmaps using a for loop and use MAKEINTRESOURCE(BASEBITMAP + i) where i is the variable that is being incremented.
I''d thank anyone who can show me a way to load bitmaps easily, i.e. without manually loading all the bitmaps. Thanks in advance
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Resource files are put inside the exe file and that''s why your exe became 4 mb big. I suppose you don''t want this
.
Here''s a tip when you want to load bitmaps in a for loop.
Suppose your bitmaps are called:
"bitmap0.bmp"
"bitmap1.bmp"
"bitmap2.bmp"
"bitmap3.bmp"
...and so on, till...
"bitmap9.bmp"
then you can load them like this:
char* fileName = "bitmapx.bmp"
for ( int i = 0; i < 10; i++ )
{
char bitmapNumber = ((char)i) + ''0'';
bitmap[ 7 ] = bitmapNumber;
LoadBitmap( fileName );
}
I suppose the above code is quite understandable and otherwise just reply again with the questions. Also note that when you have more then 10 bitmaps you need to set two characters in your filename string.
Jaap Suter

Here''s a tip when you want to load bitmaps in a for loop.
Suppose your bitmaps are called:
"bitmap0.bmp"
"bitmap1.bmp"
"bitmap2.bmp"
"bitmap3.bmp"
...and so on, till...
"bitmap9.bmp"
then you can load them like this:
char* fileName = "bitmapx.bmp"
for ( int i = 0; i < 10; i++ )
{
char bitmapNumber = ((char)i) + ''0'';
bitmap[ 7 ] = bitmapNumber;
LoadBitmap( fileName );
}
I suppose the above code is quite understandable and otherwise just reply again with the questions. Also note that when you have more then 10 bitmaps you need to set two characters in your filename string.
Jaap Suter
____________________________Mmmm, I''ll have to think of one.
Whoa,
that was a fast reply. Thanks a lot. Yeah, it works. It''s rather unconventional, but hey, what do i care, it works
Thanks
that was a fast reply. Thanks a lot. Yeah, it works. It''s rather unconventional, but hey, what do i care, it works

==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
If you didn''t mind doing a little more work, and wanted more ''meaningful'' filenames for your bitmaps, you could load in an index file first to get the filenames of your bitmaps. You could call it bitmaps.txt or something and it could be a very simple list of filenames like:
stone1.bmp
floor.bmp
player.bmp
Basically, you could either read all the filenames into an array/linked list and load each bitmap afterwards, or load each bitmap as you come across the filename while loading the index. The first way probably loads quicker. You could even allow for comments (skip any filename that starts with // or '' or however you wanted to do it), allowing you to see at a glance which bitmaps do what.
Sure, this may be overkill for 12 bitmaps
But one day you''ll have 120 and it will make sense
stone1.bmp
floor.bmp
player.bmp
Basically, you could either read all the filenames into an array/linked list and load each bitmap afterwards, or load each bitmap as you come across the filename while loading the index. The first way probably loads quicker. You could even allow for comments (skip any filename that starts with // or '' or however you wanted to do it), allowing you to see at a glance which bitmaps do what.
Sure, this may be overkill for 12 bitmaps


This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement