Archived

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

Loading a .BMP

This topic is 5882 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 trying to load a bmp file into memory, I''ve loaded the Type, Size, OffBits,... Width,Height ... and ClrImportant but what comes after that, is it the color info or what is it, I just got some wierd numbers 0, -129,-32768, 128. by the way I looked at www.wotsit.org but that didn''t help much... so can someone tell me how the data is stored in a .bmp file I''m new to this so HELP...

Share this post


Link to post
Share on other sites
Go back to wotsit and sit and read those text files. BITMAPFILEHEADER, BITMAPINFOHEADER, RGBQUAD and BYTE are structures/types that are defined in the Win32 environment, so look them up in your documentation. If you don''t have MSVC, MSDN is available online.

If you don''t figure things out by yourself, you''ll become a dependent developer, and I don''t want to see that happen to you. These things take some time and some thought, but you can do it. If you still have problems, mail me.

Lastly, there was recently a thread on this same topic. Look around for it.

Share this post


Link to post
Share on other sites
As much as possible, you shouldn''t read a file directly if you don''t define the format, because sometime in the future the format will change, and if a user updates the graphics, your program will fall over.

Win32 has a function for loading images, which you can be sure will be updated when a format changes. The function is LoadImage. Why wotsit don''t point you towards LoadImage is beyond me.

''Nuff said. I''ll enjoy watching you live, demon.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
im new to all this stuff to, but i found some good tutorials at
www.GameTutorials.com . Thanks digiben .

Share this post


Link to post
Share on other sites
quote:
Original post by Mayrel
As much as possible, you shouldn''t read a file directly if you don''t define the format, because sometime in the future the format will change, and if a user updates the graphics, your program will fall over.

Win32 has a function for loading images, which you can be sure will be updated when a format changes. The function is LoadImage. Why wotsit don''t point you towards LoadImage is beyond me.

''Nuff said. I''ll enjoy watching you live, demon.


1. He may not be using windows.
2. Since when has the bitmap format changed? It doesn''t matter anyway, because they won''t re-design bitmaps now, too many people use them. What they would do is change the BITMAPFILEHEADER.bfType parameter to something else, so that any code that trys to load it will not recognise it as a valid bitmap, so your program will not crash or anything, and your code would still work.

Share this post


Link to post
Share on other sites
quote:
Original post by python_regious
1. He may not be using windows.



Fair enough, but it seems likely that if he''s loading .BMP files, he probably is. And, even if he is using Linux/MacOS/whatever, the system or libraries provided with the system can load bitmaps.

quote:

2. Since when has the bitmap format changed? It doesn''t matter anyway, because they won''t re-design bitmaps now, too many people use them. What they would do is change the BITMAPFILEHEADER.bfType parameter to something else, so that any code that trys to load it will not recognise it as a valid bitmap, so your program will not crash or anything, and your code would still work.



Also quite true. However, if a new type of bitmap was created, then the user could use those provided his version of the system''s bitmap loading library was updated. If the program loaded the bitmap itself, it wouldn''t be able to load the new bitmap type.

When I said ''fall over'', I didn''t mean crash, I just meant that it would get confused and fail. Even if the bitmap format did change, it wouldn never be acceptable for a program to crash.

As a general rule, there''s no need to reinvent the wheel. If the system provides a function to do ''x'', then you should use that unless there''s a good reason not to. It doesn''t hurt to apply good programming practice in every situation, even if you''re only loading bitmaps.

''Nuff said. I''ll enjoy watching you live, demon.

Share this post


Link to post
Share on other sites
Okay thanks for the help

my first problem was a stupid mistake from me, I loaded the colors into int when I should have loaded them into char
(thanks Oluseyi)

but now I bumped into a new one, when I read the pixel data I only get the color from the first pixel followed by zeros. So now I wonder if this is just another stupid mistake,
how far after the first pixel is the data for the second pixel?.

Share this post


Link to post
Share on other sites