[mod removed code]

The picture resizes perfectly in Width. But i just can't get it in height. I added that fseek function, but it doesn't really seem to work. The image just gets weird, but still stays the same size in height.

  • Have you changed height value in the header? – Wiktor Czajkowski Jul 25 '15 at 18:07
  • Yes. Not quite sure they're right... int Width = bi.biWidth; int Height = bi.biHeight; bi.biSizeImage = bi.biSizeImage * n * n; bi.biWidth = bi.biWidth * n; bi.biHeight = bi.biHeight * n; – Mihai Jul 25 '15 at 18:09
  • Seems like you're using bi.biHeight value of original bitmap. First for loop iterates over rows of the original file, so you end up having the same number of them. Clever method for going back to the beginning of the row, though. I have made it more complicated. – Wiktor Czajkowski Jul 25 '15 at 18:16
  • Hmm... yes. It goes over the rows of the original files, but after it reads every row, it should write that certain row "n" amount of times. Or at least that's how i imagine it to be. I'm going to try it like you said though, just to be sure. – Mihai Jul 25 '15 at 18:27
  • Let me explain it on example: If original file has 3 rows, the Height value is 3. The first for loop will write the row to the new file correctly, replicated horizontally. On the next iteration, it will correctly go back to the beginning of the row and copy it again. 3rd iteration will be the same. Then it will stop, because i will equal 3 and, since biHeight equals 3, i < biHeight will be no longer true. That will cause loop to exit and execute the rest of the program. – Wiktor Czajkowski Jul 25 '15 at 18:39

There are 2 parts of your code causing the trouble:

  1. First one:

    row = -sizeof(Width);

    Width is just number of pixels stored in integer, so row turns out to be -1 at all times (integer is 1 byte in size). Because of this you're going back just 1 byte instead of whole row.

    For the expected result, you should do something like this:

    row = -(Width * sizeof(RGBTRIPLE));

    Above code takes number of pixels in a row and, since each pixel is made of RGB triple, multiply it by size of the RGBTRIPLE struct.

  2. Second one:

    fseek(outptr, new_padding, SEEK_CUR);
    // then add it back (to demonstrate how)
    for (int k = 0; k < padding; k++)
       fputc(0x00, outptr);

    Right now you're skipping padding in the out file, which is not how it should work. You want to skip over padding in the in file only, which is already done is copy.c, and replicate it according to factor (n) in the out file.

You must log in to answer this question.

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