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

时间:2016-06-08 15:25:52

标签: java image image-processing swt

我有一张图片

Height = 1300
Width = 1300

我将图像缩放为:     ScaledHeight = 700     ScaledWidth = 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;
}

修改 我已更新,包括答案

1 个答案:

答案 0 :(得分:2)

int width = 1300;
int scaledWidth = 700;

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

使用

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

以避免此问题。

相关问题