3

I have written pset4's resize.c and it took me a while to find the bug in my code. All I want to ask is what is the difference between bi.biHeight and abs(bi.biHeight)? With bi.biHeight some cases work, with abs(bi.biHeight) all cases work?

2 Answers 2

5

Height of a bmp image can be negative- if the image is stored top to bottom. When figuring out the size of the image, negative doesn't make sense, so it should be the absolute value of the height.

3

As per reference from msdn

bi.biHeight

can be negative or positive so to avoid that and to make sure that we always get a positive value we use

abs(bi.biHeight);

read more about bitmaps on msdn BITMAPINFOHEADER structure

here we using that value to manipulate height headers and height can't be negative so

abs(bi.biHeight);

always gives us a positive value and we have no problem and it always works. but if you don't use abs(bi.biHeight); it may give a negative value and when you got a negative value it won't work and when you get a positive value (when you're lucky) it works

You must log in to answer this question.

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