Search code examples
imagebitmapgraphic

How do I calculate the width and height of a bitmap from this file header?


00000000 42 4D 3A FE 05 00 00 00-00 00 36 04 00 00 28 00
00000010 00 00 D1 02 00 00 1D 02-00 00 01 00 08 00 00 00 
00000020 00 00 04 FA 05 00 13 0B-00 00 13 0B 00 00 00 00 

What are the values of width and height?


Solution

  • According to Wikipedia - BMP file format

    Offset (hex)    Offset (dec)    Size (bytes)    Windows BITMAPINFOHEADER[1]
    0E              14              4               the size of this header (40 bytes)
    12              18              4               the bitmap width in pixels (signed integer)
    16              22              4               the bitmap height in pixels (signed integer)
    

    With the bitmap header you posted, the width and height would be

    Width:  D1 02 00 00
    Height: 1D 02 00 00
    

    The Wikipedia link above states that

    All of the integer values are stored in little-endian format (i.e. least-significant byte first).

    If my understanding is correct, that converts to

     Width = 209 + (2 x 256) + (0 x 256^2) + (0 x 256^3) = 721
    Height =  29 + (2 x 256) + (0 x 256^2) + (0 x 256^3) = 541