Not exactly. If you read the BITMAPINFOHEADER
like so
// read infile's BITMAPINFOHEADER
BITMAPINFOHEADER bi;
fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);
to get the width, the correct is bi.biWidth
. Instead you have bi.Width
which doesn't exist.
If you then create a new BITMAPINFOHEADER
like so
BITMAPINFOHEADER out_bi;
your first two lines should be:
out_bi.biWidth = bi.biWidth * n;
and
out_bi.biHeight = bi.biHeight * n;
If you don't create a separate header, you should. You will make many more mistakes if you use the one from the in-file directly for your out-file.
Also your
bi.biSizeImage = abs(bi.biSizeImage) * n;
and
bf.bfSize = ((abs(bi.SizeImage) * n) + (bf + bi));
are totally wrong.
biSizeImage
The size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps.
source: MSDN
If you have a 3 x 3 bmp file, and multiply it by 2, even if its size was 9 (it isn't), the new size wouldn't be 18 as you have 9 * 2
. It would be 6 x 6, so 6 * 6 == 36
. But you also have to consider the padding (which may be different from the in-file's), and the fact that the size is counted in bytes
and each pixel is 3 bytes
. Each padding pixel is 1 byte
. I'll leave the math to you. It's not that hard.
bfSize
The size, in bytes, of the bitmap file.
source: MSDN
So basically, bfSize
is biSizeImage
plus the bfOffBits
. I'll leave this math to you too.
Edit for example
infile (3 × 3) + 1 padding per line
###p
###p
###p
outfile (6 × 6) + 2 padding per line
######pp
######pp
######pp
######pp
######pp
######pp
#: pixel (3 bytes)
p: padding (1 byte)
If this answers your question please accept it by clicking the gray check-mark to the left, so that it becomes green. You can also vote it up by pressing the up arrow above the check-mark. And don't forget to keep coding!