I am not sure about the title of this question, so if someone knows an appropriate one, please rename it. It's a programming related question (but doesn't involve any programming). I posted it on stack overflow but didn't get any responses so I am trying here.
I need to map a piece of rectangle (x, y, width, height) of an (original)image onto a canvas by resizing the original image. Here's a picture that explain it better.
Here's another one, bit different, so you get a better idea:
I can scale and move the image however I want. How do i figure out the scale at which to resize the original image.
I had an idea, which was to figure the bigger dimension of the given rectangle, and use that to figure out the scale, so:
Given: imageWidth, imageHeight, rectWidth, rectHeight, canvasWidth, canvasHeight (let's ignore the offsets for now)
But that doesn't work in some cases. So I wondering what's the best way to do this. ,