Java SWT:从缩放图像获取原始 X/Y 坐标

Java SWT: Getting original X/Y Coordinates from Scaled Image

我有一张图片

Height = 1300
Width = 1300

我将图像缩放为: 缩放高度 = 700 缩放宽度 = 700

我正在使用以下方法获取原始坐标:

public Coordinate GetScaledXYCoordinate(int oldX, int oldY, int width, int height, int scaledWidth, int scaledHeight)
{       
    int newX = (int)(oldX * width)/scaledWidth;
    int newY = (int)(oldY * height)/scaledHeight;

    Coordinate retXY = new Coordinate(newX, newY);
    return retXY;
}

编辑: 我已更新以包含答案

int width = 1300;
int scaledWidth = 700;

(width/scaledWidth) 的值是 1 - 你正在做整数运算而不是浮点数。

使用

int newX = (oldX * width) /scaledWidth;
int newY = (oldY * height) /scaledHeight;

避免这个问题。