I have been looking for answers here but wasn't able to make the code work, so I am hoping someone will be able to help with this question. I have been working on pset4 resize for several days now and I must be doing something fundamental wrong, because small won't change size (just colour). I have put some of the code below. I haven't changed much outside this section. Thanks in advance!
//formula for padding int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
// write outfile's BITMAPFILEHEADER
fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);
bf.bfSize = (bf.bfSize * n) + padding;
// write outfile's BITMAPINFOHEADER
fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);
bi.biWidth = bi.biWidth * n;
bi.biHeight = bi.biHeight * n;
bi.biSize = bi.biHeight * (bi.biWidth + padding);
// iterate over infile's scanlines, adjusting height
for(int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
for(int r = 0; r < n; r++)
{
// iterate over infile's scanlines, adjusting width
for(int j = 0; j < bi.biWidth; j++)
{
//temporary storage
RGBTRIPLE triple;
//read from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
//iterate size of outfile by n
for(int s = 0; s < n; s++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
//skip over padding
fseek(inptr, padding, SEEK_CUR);
// determine padding for scanlines
for(int k = 0; k < padding; k++)
{
fputc(0x00, outptr);
}
//return pointer to just after headers
fseek(inptr, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER), SEEK_SET);
}
}