### Author Topic: Calculating correct offset for a scaled image  (Read 2370 times)

#### stevefsp

Scenario:

Two images, a base texture and an overlay image.  The base image is 'full size', while the overlay is several factors smaller.  In Designer the overlay image needs to be scaled and offset such that it is in the exact correct position on the base image.

Question:

What is the formula to calculate the required offset for a scaled image such that it is at the same position over its base texture as it was in Photoshop or other image editing software?  (Eye-balling it isn't accurate enough.)

Basically, I'm using masks that cover only part of the base texture.  The masks need to be at the same base texture offset as they are in Photoshop.  But since the Transform2D is applying the scale before the translation I'm having problems calculating the correct offset.

Example:

In Photoshop:

Base texture: 2048x2048
Mask: 512x512 positioned over the base texture at a (top, left) offset of (1536, 752).

In Designer with Transform2D:

Scale is easy, /2 twice to get (4, 0, 4, 0).

The un-scaled offset is (0.75, 0.367).  But that doesn't work after the scaling.  The correct scaled x-offset is -1.5 (-2 * 0.75).  But when I use that formula for the y-offset it is obviously wrong.

Hi Steve,