Scaling a bitmap down (ratio)


#1

In section 16.9 in the book it says “a sample size of 1 has one final horizontal pixel for each horizontal pixel in the original file, and a sample size of 2 has one horizontal pixel for every two horizontal pixels in the original file.” The next line has me a little puzzled.
“So when inSampleSize is 2, the image has a quarter of the number of pixels on the original.”

Maybe I’m not getting something but wouldn’t that mean if you have 1 pixel for every 2 pixels in the original file, you would now have an image HALF the size of the original? Am I reading this wrong?

Thanks


#2

This is geometry, my friend.
If you halve the length and width of a rectangle or square, you reduce it’s area by four times.
Imagine a 4x4 square of area 16 (a pixel is equivalent to a unit of area). If you reduce it’s area to 2x2, it will now have an area of 4.
Hope that helps.


#3

You are ONLY thinking about the horiz axis (x). What about the vertical axis (y)? The inSampleSize subsamples on both the axis. So, when the inSampleSize is 2, then 1 out of every 2 pixels on the x-axis and 1 out of every 2 pixels on the y-axis is decoded. As a result, the decoded image is 1/2 the width of the original image and 1/2 the height of the original image. Consequently, this implies that the decoded image has (1/2 * 1/2) 1/4 the number of pixels in comparison to the original image.

In other words, if inSampleSize = x, then the x number of pixels on both dimensions width, height map to a single pixel in the decoded bitmap.


#4

Thank you! You’re right. I was missing that.