S Kh
S Kh

Reputation: 105

What should we do with a Bitmap file when it's rowsize isn't multiple of 4?

I am writing a program to rotate an image. The Image format is Bitmap and according to the http://en.wikipedia.org/wiki/BMP_file_format the rowsize of a bitmap image should be multiple of 4. My input image isn't so and when I write new image to a file, it isn't what it should be. Of course first I read the data part to an array of pixels and after that I rotate that array. If more information is needed, please tell me.

Of course my previous problem had been solved but I don't know why c++ count the size of this structure 56 byte ?

Here is the structure:

struct  Bitmap_Header
{
    char H_Signature[2];
    unsigned int H_Filesize;
    int H_Reserved;
    unsigned int H_DataOffset;
    unsigned int H_Size;
    int H_Width;
    int H_Height;
    short int H_Planes;
    short int H_BitCount;
    unsigned int H_Compression;
    unsigned int H_Imagesize;
    int H_XPixelsPerM;
    int H_YPixelsPerM;
    unsigned int H_ColorsUsed;
    unsigned int H_ColorsImportant;
};

Upvotes: 0

Views: 365

Answers (1)

Photon
Photon

Reputation: 3222

When you write an image to a bmp file, you're supposed to pad each scan line so that its size in bytes is a multiple of 4. Just add extra 0 bytes at the end of each row.

Upvotes: 0

Related Questions