オンラインで CS50 コースを受講していて、ビットマップをスケーリングする必要があります。横に伸ばすことはできますが、問題を引き起こしているのは、縦に伸ばす方法です。解像度で画像のサイズを 2 倍にしましたが、ストレッチは画像の下半分でのみ発生し、画像の上半分は真っ白です。すでに reddit と here で fseek を検索しようとしましたが、画像が水平方向にしか伸びない理由がわかりません。
これは私のコードの一部です:
n = 2; // scale up by factor 2
bi.biWidth = bi.biWidth * n; // double width
bi.biHeight = bi.biHeight * n; //double hight
//iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
for (int m = 0 ; m < n; m++) // repeat process n-times to copy lines vertically
{
// iterate over pixels in scanline
for (int j = 0; j < bi.biWidth; j++)
{
// temporary storage for RGB values to be copied
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// write RGB triple to outfile n-times to stretch horizontally
for (int k = 0; k < n; k++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
fseek(inptr, -sizeof(bi.biWidth), SEEK_CUR); // go back to the beginning of the line
}
}