Save additional info in a BMP

Started by
5 comments, last by Ravyne 15 years, 11 months ago
Hi there, I'm working on an rpg here. But I got a question, i want to have a map file that contains a BMP as background, but i dont want the additional info and the BMP itself in a different file. Is there a way to get them in the same file? Thanks Robin
Microsoft: “You’ve got questions. We’ve got dancing paperclips.” – unknown
Advertisement
Technically, you can put any data you like at the end of the file, or after the BITMAPINFOHEADER struct - that's what the bmOffBits member is for.

In practice though, doing this could cause the BMP to not load on some image viewers, and the information will be lost if you save the image.
Well, it doesnt have to be viewable by image viewers. It's a map class
Microsoft: “You’ve got questions. We’ve got dancing paperclips.” – unknown
If you want to combine the image with data about the image, PNG has a chunk type for arbitrary data you can use, but alternatively you could just define your own file format for maps.
BMP's don't have an official way to embed metadata. You can fake it like Evil Steve describes but there are so many crappy BMP loaders out there that you're virtually guaranteed to break some of them, plus you run the risk of MS extending the format again and having your stuff interfere with thiers.
-Mike
What kind of meta data?

If you need something per-pixel (such as collision map), you can use one of bitmap channels.

Then there's TIFF. That one was designed for extensibility, while it still remains editable and viable.
I would argue that its bad form to try and shoe-horn your extra data onto a bitmap file, so rather than adding additional map data onto the BMP format, why not add the bitmap data to your own map format? Just have your map tool import a bitmap and include it in it's data set.

That way, you don't have to worry about what happens when your user decides to open the map in paint and, for whatever reason, save the file instead of simply closing it.

throw table_exception("(? ???)? ? ???");

This topic is closed to new replies.

Advertisement