This is the code I have written but it fails to produce the intended result. I am really not able to figure out why it's wrong. Can somebody help me?


if (image[i][j].rgbtRed > 255)
    image[i][j].rgbtRed = 255;

Do you understand why you have to check for values over 255? You are doing it too late.

A BYTE has 8 bits. That means the maximum value it can hold is 255. You are calculating the new value and storing it directly into image[i][j].rgbtRed for example. At that point, if the calculated value is > 255, it will be truncated when you assign it. So it's too late.

Let's say the new value is 300. In binary, that's

100101100  (9 bits)

so the top bit is ignored and you end up storing

00101100   (8 bits)

which is 44.

You must log in to answer this question.

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