How to mount a BMP header (Bitmap) in C

Hello.

I am wanting to mount a BMP in C language. I only get the image data, data size, width, height, bpp.

I managed to mount the following BMP header structure:

struct BMPHeader
{
    uint16 signature;           // 0-1   magic chars 'BM'
    uint32 fileSize;            // 2-5   uint32 filesize (not reliable)
    uint32 filler1;             // 6-9   uint32 0
    uint32 bitmapOffset;        // 10-13 uint32 bitmapOffset
    uint32 infoSize;            // 14-17 uint32 info size
    int32 width;                // 18-21 int32  width
    int32 height;               // 22-25 int32  height
    uint16 nPlanes;             // 26-27 uint16 nplanes
    uint16 bpp;                 // 28-29 uint16 bits per pixel
    uint32 compression;         // 30-33 uint32 compression flag
    uint32 imageSize;           // 34-37 uint32 image size in bytes
    int32 biXPelsPerMeter;      // 38-41 int32  biXPelsPerMeter
    int32 biYPelsPerMeter;      // 32-45 int32  biYPelsPerMeter
    uint32 colorsUsed;          // 46-49 uint32 colors used
    uint32 importantColorCount; // 50-53 uint32 important color count
};

As mentioned above, much of the header information I receive from an application in java, except these:

int32 biXPelsPerMeter;      // 38-41 int32  biXPelsPerMeter
int32 biYPelsPerMeter;      // 32-45 int32  biYPelsPerMeter

Can anyone tell if these two variables come from the calculation of the variables I received? I didn't quite understand what they represent...

Thank you right now.

Author: SylvioT, 2019-03-13

1 answers

biXPelsPerMeter it is the horizontal resolution in pixels per meter suggested for the device that will display the bitmap. The application can use this value to select within a group of bitmaps which Image best suits the characteristics of the display device.

biYPelsPerMeterit is the vertical resolution in pixels per meter suggested for the device that will display the bitmap. The application can use this value to select within a group of bitmaps which Image best fits the characteristics of the display device.

These values were typically used in bitmap fonts. The first bitmap fonts were fixed at 96 DPI so they put these properties so that the glyphs that best suited the device on which it would be rasterized could be selected.

For images these values have no significance. But if you want to know how to calculate the values:

biXPelsPerMeter = Round(width / comprimento do dispositivo em metros)
biYPelsPerMeter = Round(height / altura do dispositivo em metros)
 0
Author: Augusto Vasques, 2019-03-14 02:03:15