0

I am getting Error -254 ,Have i defined my outfile's header correctly?

// write outfile's BITMAPFILEHEADER
BITMAPFILEHEADER bf_resize;
BITMAPINFOHEADER bi_resize;

bi_resize.biWidth=bi.biWidth*n;
bi_resize.biHeight=bi.biHeight*n;

 int padding1 =  (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
 int padding2=(4 - (bi_resize.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;

bi_resize.biSizeImage=((bi_resize.biWidth*sizeof(RGBTRIPLE)+padding2)*(abs(bi_resize.biHeight)*sizeof(RGBTRIPLE));
bf_resize.bfSize=bi_resize.biSizeImage+54;

// write outfile's BITMAPINFOHEADER
fwrite(&bf_resize, sizeof(BITMAPFILEHEADER), 1, outptr);
fwrite(&bi_resize, sizeof(BITMAPINFOHEADER), 1, outptr);
0
1

Maybe you should initialize bf_resize and bi_resize to copies of bf and bi (they should be the same except for four size-related fields), using for example

BITMAPFILEHEADER bf_resize = bf;
BITMAPINFOHEADER bi_resize = bi;

I also see a problem with

bi_resize.biSizeImage=((bi_resize.biWidth*sizeof(RGBTRIPLE)+padding2)*(abs(bi_resize.biHeight)*sizeof(RGBTRIPLE));

Here you multiply the line length in bytes bi_resize.biWidth*sizeof(RGBTRIPLE)+padding2 with the number of lines abs(bi_resize.biHeight) times the bytes per pixel sizeof(RGBTRIPLE), even though the line length has already been converted to bytes. Removing that last *sizeof(RGBTRIPLE) will fix that one.

0

bi.biWidth, bi.biHeight etc should be the names of the new, resized headers. Run peek against your version and staffs (~cs50/pset4/peek student.bmp staff.bmp) and might find that changing names of headers might do the trick

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .