How to mount a BMP header (Bitmap) in C

Asked

Viewed 130 times

0

Hello.

I’m looking to build a BMP in C-language. I only receive image data, data size, width, height, bpp.

I was able to mount the following header structure of BMP:

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, a lot of the header information I get from a java application, except this:

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 did not understand well what they represent...

Thank you in advance.

1 answer

0

biXPelsPerMeter is the suggested horizontal pixel per meter resolution 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.

biYPelsPerMeteris the suggested vertical resolution in pixels per meter 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 normally used in bitmap sources. The first bitmap fonts were fixed at 96 DPI so they placed these properties so that they could select the glyphs that best fit the device where would be Rasterized.

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)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.