Dealing with padding in a BMP file in C

后端 未结 3 1399
一生所求
一生所求 2020-12-20 00:45

I am trying to edit a BMP file in C. My code works for BMP files with no padding but I am having trouble dealing with padding.

There are a few other questions on BMP

3条回答
  •  生来不讨喜
    2020-12-20 01:07

    Something like:

    ...
    
    int originalLineSize = width * 3;
    int workLineSize = originalLineSize + 4 - originalLineSize % 4;
    
    for (int a = 0; a < bmpArraySize; ++a) {
        if ((a % workLineSize) >= originalLineSize)
            bmpArray[a] = 0x00;
        }
        else if (bmpArray[a] < 127) {
            bmpArray[a] = 0;
        ...
    }
    

提交回复
热议问题