I was having issues with my headers because I chose to create a separate header file for my new header changes. However, my code was not passing the check50. Upon researching and questioning, I found out that bfSize could be written using bfOffBits.
BITMAPINFOHEADER bii; bii = bi; BITMAPFILEHEADER bff; bff = bf; int oldWidth = bi.biWidth; int oldHeight = abs(bi.biHeight); // determine padding for scanlines int padding = (4 - (oldWidth * sizeof(RGBTRIPLE)) % 4) % 4; bii.biWidth = bii.biWidth * number; bii.biHeight = bii.biHeight * number; int newPadding = (4 - (bii.biWidth * sizeof(RGBTRIPLE)) % 4) % 4; bii.biSizeImage = ((sizeof(RGBTRIPLE) * bii.biWidth) + newPadding) * abs(bii.biHeight); bff.bfSize = bff.bfOffBits + bii.biSizeImage; // write outfile's BITMAPFILEHEADER fwrite(&bff, sizeof(BITMAPFILEHEADER), 1, outptr); // write outfile's BITMAPINFOHEADER fwrite(&bii, sizeof(BITMAPINFOHEADER), 1, outptr);
What I don't understand is why
bff.bfSize = bff.bfOffBits + bii.biSizeImage;
is working? What is bfOffBits and how does it calculate the entire size of the file, including the headers? I understand that biSizeImage gives the size of the bmp and padding, but how does bfOffBits give the size of BITMAPFILEHEADER and BITMAPINFOHEADER?