2016-06-08 169 views
0

我有其中爪哇SWT:獲取原始x/y座標從縮放圖像

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; 
} 

編輯: 醫管局我VE更新,包括回答

+0

您可以添加示例輸入和您的方法的相應輸出嗎? – Baz

回答

2

隨着

int width = 1300; 
int scaledWidth = 700; 

(width/scaledWidth)值 - 你正在做的整數運算不是浮點。

使用

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

以避免此問題。

+0

斑點! +1 – Baz

+0

感謝@ greg-449的幫助 –