BITMAP 的正确步幅公式

Correct stride formula for BITMAP

Calculating Surface Stride

In an uncompressed bitmap, the stride is the number of bytes needed to go from the start of one row of pixels to the start of the next row.

以上内容来自BITMAPINFOHEADER structure,绝对有道理。

同一站点给出了以下计算步幅的公式:

For uncompressed RGB formats, the minimum stride is always the image width in bytes, rounded up to the nearest DWORD. You can use the following formula to calculate the stride:

stride = ((((biWidth * biBitCount) + 31) & ~31) >> 3)

假设图片宽度为 600,高度为 800,1bpp

我希望步幅为 600/8 = 75...但是上面的公式给出了 76!

我正在使用 (w + 7) / 8 并获得预期的 75...

仍然看到来自 Microsoft 的上述公式让我充满疑问 - 这个公式正确吗?

75 没有四舍五入到最接近的 DWORD。 DWORD 每个都是 4 个字节。 76 是 4 的下一个最高倍数。

公式正确(它在除以得到最终字节数之前四舍五入到下一个 DWORD 位)。您似乎只是四舍五入到最接近的字节,这不是一回事。