# Pset4 resize.c - bfsize & bisizeimage formulas

First of all thanks for your time.

Taking cs50 through edX - struggling as all alone here and videos / lectures are burnt out for information - need real people! Online cs50 really does assume a lot of the learner.

I'm struggling big time with recover, just took a 5 day break. currently trying to create the formulas for the new files headers, as follows:

// new width
bi.biWidth = bi.Width * n;
// new height
bi.biHeight = bi.Height * n;
// The new size, in bytes, of the image
bi.biSizeImage = abs(bi.biSizeImage) * n;
// The new size, in bytes, of the bitmap file (includes headers)
bf.bfSize = ((abs(bi.SizeImage) * n) + (bf + bi));

are these correct? if not please help, don't be cryptic, i seriously am at wits end :)

thanks

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

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)