Search code examples
encodingmetadatabmp

Get file information .bmp


I am fairly new to .bmp I want to learn more about it. I have a .bmp file now and I wonder where I would get the headerinformation, file information etc. Baisically, I need the written code behind the image (not open the image itself, but see what is written there - the bitmap, the header etc.). I want to access the information you can read on wikipedia here

I do not know how to open the file to get these information... I though I can read it somehow in a texteditor..

Can anyone pinpoint me in the right direction?


Solution

  • You said:

    Assuming I want to find in the HEX Code the size of the image. How would I get that HEX Code

    So, pick any BMP file and open it in a hex editor. From the specification you link to:

    All versions of BMP format files begin with the following 14-byte [file] header:

    [...]

    Version 4.x BMP files begin with the same 14-byte header as v2.x and v3.x BMP files. The file header is also followed by a bitmap header, which is an expanded version of the v3.x bitmap header

    typedef struct _Win4xBitmapHeader
    {
        DWORD Size;            /* Size of this header in bytes */
        LONG  Width;           /* Image width in pixels */
        LONG  Height;          /* Image height in pixels */
        [...]
    } WIN4XBITMAPHEADER;
    

    So the first header is 14 bytes. The 15th-18th byte define the second header's lenght. Then follow two longs, of four bytes each, giving you the width and height of the image.

    So byte 19-22 give the width, byte 23-26 give you the height - for a version 3 or 4 bitmap. Version 1 and 2 use one respectively two bytes for each dimension, so be sure to inspect the bitmap version first (by analyzing the header size).