1

I figured that in order to resize an image using a float for the scale factor I could pick the pixels to copy from the source image's scanlines as follows:

For example, if the source image is 3px wide and we want to scale it by a factor of 0.5 then we would have an output image that's 3*0.5 = 1.5px or 2px wide if we round up.

Next we go to the original scanline and pick the pixel that is 1/2 the width across (that would be the second one since 3/0.5 is 1.5 or 1 as an int) and the one that is 2/2 across is the third pixel.

In summary

new[0] = old[1]
new[1] = old[2]

However, in the walkthrough video the sequence is this:

new[0] = old[0]
new[1] = old[2]

Can anybody help me understand how this sequnce is created?

3

I'm dealing with that at the moment, and as far as I can tell the form is

newArray[i] = oldArray[(int)floor(i / factor)]

Then, if factor = 0.5

floor(0/0.5) = 0 /* newArray[0] = oldArray[0] */
floor(1/0.5) = 2 /* newArray[1] = oldArray[2] */
floor(2/0.5) = 4 /* newArray[2] = oldArray[4] */ 

And so on.

| improve this answer | |

You must log in to answer this question.

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