0

HI Here is my code doesn't resize properly, // iterate over infile's scanlines for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++) { // 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);
         for (int l = 0; l < n; l++) {
         for (int p = 0; p < n; p++) {


        // write RGB triple to outfile
        fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);

      } 
     } 
    }
    // skip over padding, if any
    fseek(inptr, newpadding, SEEK_CUR);

    // then add it back (to demonstrate how)
    for (int k = 0; k < newpadding; k++)
        fputc(0x00, outptr);
}

// close infile
fclose(inptr);

// close outfile
fclose(outptr);

// that's all folks
return 0;

}

1 Answer 1

1

It looks like you are trying to scale the image up both horizontally and vertically with the l and p for loops. Vertical scaling can't be done this way. The pixels will be written out sequentially, so instead of scaling the image horizontally n times, each pixel will be written n * n times, which will wrap to the next line and generally corrupt the image.

Instead, you need to scale up the horizontal line by printing each pixel n times, and then adding the padding. You then need to go back to the beginning of the line until you have n copies in total of each line.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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