I've stuck for days in this resize problem, first, here's my code
BITMAPINFOHEADER bi1 = bi;
bi1.biWidth = bi.biWidth * n;
bi1.biHeight = bi.biHeight * n;
int padding1 = (4 - (bi1.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
bi1.biSizeImage = (bi1.biWidth* sizeof(RGBTRIPLE) + padding1) * abs(bi1.biHeight);
BITMAPFILEHEADER bf1 = bf;
bf1.bfSize = bi1.biSizeImage + 54;
// write outfile's BITMAPFILEHEADER
fwrite(&bf1, sizeof(BITMAPFILEHEADER), 1, outptr);
// write outfile's BITMAPINFOHEADER
fwrite(&bi1, sizeof(BITMAPINFOHEADER), 1, outptr);
// determine padding for scanlines
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
// write the pixels with n times height
for (int p = 0; p<n; p++)
{
// 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);
}
// skip over padding, if any
fseek(inptr, padding, SEEK_CUR);
// add padding to out file
for (int k = 0; k < padding1; k++)
{
fputc(0x00, outptr);
}
}
}
// close infile
fclose(inptr);
// close outfile
fclose(outptr);
// that's all folks
return 0;
}
I know it's no there yet, but I have some question:
How does the BMP print out the pixel? ( Let's say biWidth is 12, Height is positive, so when it's creating, it prints from the bottom left pixel and works all the way up til it reach headerinfo? Everytime it reach position 12 of a line, does it automatically jump on the upper line and continue printing at pos 13 right up the head of pos 1 where it starts?
In the walkthrough video, Zamyla mentioned using fseek to return to the start pos and keep printing, what's the logic behind that fseek? ( I do know how fseek works, I just don't understand it in this resize case) Sorry for the long question. Please help...