I have a few problems with my code but my main problem right now is being unable to even open the resized image. I think the problem is with writing updated header info to the outfile. I've thrown in my code here, any help would be greatly appreciated.
BITMAPFILEHEADER bf;
fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);
BITMAPINFOHEADER bi;
fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);
//duplicate header files for outfile
BITMAPINFOHEADER obi;
fread(&obi, sizeof(BITMAPINFOHEADER), 1, inptr);
BITMAPFILEHEADER obf;
fread(&obf, sizeof(BITMAPFILEHEADER), 1, inptr);
obi.biWidth = bi.biWidth * n;
obi.biHeight = bi.biHeight * n;
int opadding = (4 - (obi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
obi.biSizeImage = (obi.biWidth * sizeof(RGBTRIPLE) + opadding) * abs(obi.biHeight);
obf.bfSize = obi.biSizeImage + 54;
// write outfile's headers
fwrite(&obf, sizeof(BITMAPFILEHEADER), 1, outptr);
fwrite(&obi, sizeof(BITMAPINFOHEADER), 1, outptr);
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
//resize vertically
for (int vert = 0; vert < n; vert++)
{
fseek(inptr, i * (bi.biWidth * sizeof(RGBTRIPLE) + padding) + 54, SEEK_SET);
// iterate over pixels in scanline
for (int j = 0; j < bi.biWidth; j++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// write RGB triple to outfile
fwrite(&triple, sizeof(RGBTRIPLE), n, outptr); // write 'n' times of the pixel to outfile
}
// add new padding value to outfile
for (int k = 0; k < opadding; k++)
{
fputc(0x00, outptr);
}
}
// skip over old padding, if any
fseek(inptr, padding, SEEK_CUR);
}