如何修复 bfSize 字段中的 header
How to fix header in bfSize field
我在哈佛 CS50 的第 4 周。我目前正在研究调整大小——因此将现有的 BMP 放大一个特定的因子(1 到 100 之间)。
我的代码可以准确地编译和调整图像大小,但是当 运行 CS50 的 Check50 指示 bfSize 字段中出现意外错误时,例如在 header 字段 bfSize 中预期为 0xae,而不是 0x5a。
我对编程完全陌生,所以请原谅我提出任何愚蠢的问题。
这是我测试代码时 Check50 returns 的结果:
:) resize.c and bmp.h exist.
:) resize.c compiles.
:) doesn't resize small.bmp when n is 1
:( resizes small.bmp correctly when n is 2
expected 0xae, not 0x5a in header field bfSize
:( resizes small.bmp correctly when n is 3
expected 0x132, not 0x5a in header field bfSize
:( resizes small.bmp correctly when n is 4
expected 0x1e6, not 0x5a in header field bfSize
:( resizes small.bmp correctly when n is 5
expected 0x306, not 0x5a in header field bfSize
:( resizes large.bmp correctly when n is 2
expected 0x6f6, not 0x1e6 in header field bfSize
:( resizes smiley.bmp correctly when n is 2
expected 0x336, not 0xf6 in header field bfSize
:( resizes smiley.bmp correctly when n is 3
expected 0x6f6, not 0xf6 in header field bfSize```
我没有 small.bmp(所以我不能尝试)但我建议更改 :
newBf.bfSize = bi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
到
newBf.bfSize = newBi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
您仍在使用旧的 bi
而不是 newBi
来计算 newBf.bfSize
。
我在哈佛 CS50 的第 4 周。我目前正在研究调整大小——因此将现有的 BMP 放大一个特定的因子(1 到 100 之间)。
我的代码可以准确地编译和调整图像大小,但是当 运行 CS50 的 Check50 指示 bfSize 字段中出现意外错误时,例如在 header 字段 bfSize 中预期为 0xae,而不是 0x5a。
我对编程完全陌生,所以请原谅我提出任何愚蠢的问题。
这是我测试代码时 Check50 returns 的结果:
:) resize.c and bmp.h exist.
:) resize.c compiles.
:) doesn't resize small.bmp when n is 1
:( resizes small.bmp correctly when n is 2
expected 0xae, not 0x5a in header field bfSize
:( resizes small.bmp correctly when n is 3
expected 0x132, not 0x5a in header field bfSize
:( resizes small.bmp correctly when n is 4
expected 0x1e6, not 0x5a in header field bfSize
:( resizes small.bmp correctly when n is 5
expected 0x306, not 0x5a in header field bfSize
:( resizes large.bmp correctly when n is 2
expected 0x6f6, not 0x1e6 in header field bfSize
:( resizes smiley.bmp correctly when n is 2
expected 0x336, not 0xf6 in header field bfSize
:( resizes smiley.bmp correctly when n is 3
expected 0x6f6, not 0xf6 in header field bfSize```
我没有 small.bmp(所以我不能尝试)但我建议更改 :
newBf.bfSize = bi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
到
newBf.bfSize = newBi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
您仍在使用旧的 bi
而不是 newBi
来计算 newBf.bfSize
。