First of all, the block for the bitmap data should be created like this:
Code:
char image_data[width*length*bytes_per_pixel];
//White background
memset(image_data, 0xFF, width*length*bytes_per_pixel);
Assuming you're using 24-bit color, each pixel uses a whole byte for each primary color. BMP files are stored in BGR format, so, if I wanted to make the pixel at (x, y) red, I would do this:
Code:
enum {
BLUE_OFF = 0,
GREEN_OFF,
RED_OFF
};
image_data[x*width + y + BLUE_OFF] = 0x00;
image_data[x*width + y + GREEN_OFF] = 0x00;
image_data[x*width + y + RED_OFF] = 0xFF;
If you're using 16-bit color, a little more trickery is required. And if you're in 8-bit color, you need a palette.