tags:

views:

26

answers:

1

I have a structure such as

   typedef struct  FT_Bitmap_
  {
    int             rows;
    int             width;
    int             pitch;
    unsigned char*  buffer;
    short           num_grays;
    char            pixel_mode;
    char            palette_mode;
    void*           palette;

  } FT_Bitmap;

defining my bitmap data

I want to create a valid bmp file from this structure. How can I do that?

A: 

Take a look at:

http://en.wikipedia.org/wiki/BMP_file_format

Write out the header, the palette and the data.

Just take care when you write the bitmap data. It's "upside-down" - the first pixel in data is the left-bottom corner pixel.

Vitor Py
thank you. The thing is, I dont know which elements in my struct would go to which elements in the bmp file.
First you print out the generic BMP header. After that, you write the DIB header - this is where you print out height, width and the other information you have on your struct. After that, you pallete (also in your header). And, at last, go through you buffer (in your header again), writing pixel per pixel in the output file.You might want to take a look at this example:http://www.kalytta.com/bitmap.h
Vitor Py