BMP Class

Started by
14 comments, last by Myth000 18 years, 7 months ago
Hello, I want to write a bitmap writer. I found enough readers but no bitmaps writer, one that actually just plots pixels and doesn't mess with hdc or anything else. Just with simple functions:

void PlotPixel(const int x, const int y, const int r, const int g, const int b);
void Open(const char *file, const int dimensionX, const int dimensionY);
void Close();


I found things like this: http://atlc.sourceforge.net/bmp.html But then still if I want to write that, how can I write to 0002h? So how to write to hex addresses in hex values. Thank you, - Myth
Advertisement
To make the compiler view a value a hexidecimal, prefix it with 0x. For example, to write the value 1Bh to index 12h of an array:
arr[0x12] = 0x1b;
Jooleem. Get addicted.
And then how to write that array to the file?
If you want to write a BMP file, try using The BMP file format. Here is some info.
As for file IO operations in C, you can find a nice tutorial here.

EDIT: Oh, I just realized you never mentioned BMP specifically, just bitmaps in general. In that case, you can make up your own format, or try something simple like PPM.

[Edited by - Peregrin on September 11, 2005 7:22:44 AM]
Jooleem. Get addicted.
I don't know the exact defination, but I mean those 24 or 32 bit bmp's you can make in paint uh...
The bitmaps MS Paint saves are Windows Bitmap files (BMP). The format is a little tricky, although it is not rocket science.
If this is your first experience with file formats, I would strongly suggest you try writing a small program that saves PPM files first. It can be a great introduction to the subject, and is also a semi-useful format. Most image viewers support PPM files, so will be able to view the files you save in IrfanView, for example.
Jooleem. Get addicted.
I'll do that then.
PPM seems pretty easy to do.. well at least it's just plain ascii.
Yup, that was easy and it works.
I can now actually create patterns and gradients YAY:-D

Thanks man,
- Myth
Glad to help. :)

I remember the first time I actually saved an image from my code. It was a simple blur, if I recall correctly. Opening it in an image viewer and actually seeing the picture was really amazing! I hope you will have as much fun with this as I had.
Jooleem. Get addicted.
Having the fun now. Calculating transparants etc...
Though I'm not sure about the color amount.
I want RGB colors. With max of 255 255 255.
Then the max color value must be 255 * 255 * 255 = 16 581 375?
That seems pretty correct, but then the image is considered invalid.
EDIT: Max = <65536

This topic is closed to new replies.

Advertisement