I have been stuck at resize(less comfortable) for 3 weeks now. I have written the following code and can't tell why its not resizing and instead IDE is showing that the image is unsupported or invalid. Please check for problems... `

[hid code per academic honesty guidelines]

BTW I tried using malloc in full_pixel variable(to store multiple pixels) but it didn't work so i am not using dynamic allocation


1 Answer 1


Your issue is in your use of fwrite.

fwrite(&full_pixel, sizeof(RGBTRIPLE), factor, outptr);

Please see the answer to this question for an explanation why using factor as an argument to fwrite won't work.

edited to reply to second issue
Another problem, which is why you are getting "invalid format" errors is that you are writing the headers in the wrong order.

A bitmap format first has the BITMAPFILEHEADER, then the BITMAPINFOHEADER, and then the pixels.

Be sure you write those to the outfile in the correct order (bf then bi and not how you have it now)

  • instead of fwrite(&full_pixel, sizeof(RGBTRIPLE), factor, outptr); i wrote.... for(int pixel = 0; pixel < factor; ++pixel) fwrite(&full_pixel[pixel], sizeof(RGBTRIPLE), 1, outptr); to remove the factor from it but it still didn't run
    – TheGeek
    Feb 3, 2019 at 16:24
  • see my edited answer
    – curiouskiwi
    Feb 3, 2019 at 21:26

You must log in to answer this question.

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