I'm resizing an image based on a non-integral conversion factor (a bmp image, in fact). I understand how resizing works, just non with a decimal number. For instance, if the factor were 2, I would simply write the individual pixels twice to the output file. You can't really write 1.5 pixels if the factor were, say, 1.5. Conceptually, how might this play out?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Don't think of the process as "where would this pixel go?", but rather as "from where did that pixel came?".
Then, it's easy to see that each pixel in the final picture will come from a position at a fractional coordinates in the original image, that just means it will have a color that is a weighted average of the near pixels.
That's why Photoshop (and others) lets you choose the subsampling algorithm. Some are prettier but use more origin pixels, or need more precise math, while others are fast and doable with integer numbers but not so good looking.
This is actually a big topic. What you are asking about is called image resampling. And there are many different algorithms that can be used. See the wikipedia article for a basic introduction.
But as Javier hinted at, you dont generally take a pixel and write out a scaled version. Rather, you look at a destination pixel, and figure out what source pixels you need to reference and how to weigh them to calculate the destination pixel.