Creating a Bitmap from code

Hi everyone! Im a little new to c++ and this forum, so please correct me if this is not in the right topic area. My question is how can I create a Bitmap image from code? I have been researching this for a while now, but I cant understand how to make the whole thing work. The only thing I managed to understand about a Bitmap image is that it works as a multidimensional array, or a 2D array, and each pixel in the image is a position in the array. I already know how to create the image file, but now I want to be able to add pixel data (or color data to the array positions) to this file. Any help is appreciated, thank you!

P.S: I put my code for creating the bitmap image below, please tell me if this is not the proper way of doing this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <fstream>
using namespace std;



int main ()
{
	ofstream myImage;
	myImage.open("My New Bitmap.bmp");
	
	//cool stuff goes here...

	myImage.close();
}
Topic archived. No new replies allowed.