The code compiles, but the image file is now of an invalid or unsupported type. What did I do wrong here?

And if my calculation for the padding and image-size is wrong, let me know about that as well. Thanks.

Edit: I just updated the question.

I've found the correct formula for the biSizeImage and bfSize values and put those into the code, but I still get the same "unsupported or invalid file type" error as before.

Edit2: Made another update. I got some pseudocode from a short video by Zamyla about resize.c and I'm trying to use that here. It's the one for the recopy method, but I'm having trouble figuring out how to implement it correctly.

This is the pseudocode:

for each row
    for n - 1 times
        write pixels and padding to outfile
        send infile cursor back
    write pixels and padding to outfile
    skip over infile padding

Also, if possible, I'd like to also like some help implementing the rewrite method (the one with the array). I didn't get what to put into the array and where to use it exactly, so some help there would be appreciated. I'll try to do whichever one is easier and simpler, but I need some help in understanding them and implementing them. Thanks.

Never mind. I'll make another post for the vertical resize.

1 Answer 1


I'll point out to you the critical error so you can at least see your img an analyze what's going wrong.

bi.biHeight can be positive or negative, and it happens that the image you're dealing with in this problem has a negative bi.biHeight. That will mess up your code here:

// iterate over infile's scanlines
for (int i = 0, biHeight = img_height; i < biHeight; i++)

So what you need to do is make sure biHeight is always positive. Can you think of a way to do it?

After that, you'll come to realize that you're skipping the new padding when you should be skipping the old one.

And finally you'll see that you still need to resize the image vertically, because your code will only resize it horizontally after the fixes I've just mentioned.

I'll let you try to figure that one out by yourself (but Zamyla can help you greatly here: https://www.youtube.com/watch?v=zOylgRdzv_U)

  • Someone on Facebook pointed out the padding and negative bi.Height problems to me. I've changed the call to fseek to make it skip over the old padding, but I'm not sure if the padding code is correct now. As for making biHeight positive, do I add it to its own value? But that'll make it 0, so I'm still lost there. I'll watch Zamyla's walkthrough again, but I'll probably have to ask again here or on Facebook Here's the code with the changes (posted it on Pastebin): pastebin.com/4Tu8qUgK. Oh wait, the abs() function. I'll just use that for biHeight. Oct 31, 2016 at 11:01
  • Okay, it's at least resizing it correctly, if you can call it that without it coloring the image correctly. There's some green and white up top, but it doesn't fill the whole image so the rest is black. Here's the updated code: pastebin.com/4Tu8qUgK Oct 31, 2016 at 11:52

You must log in to answer this question.

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