gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:33:46 25 4
gpt4 key购买 nike

我有一张图片

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 - 您正在执行整数算术而不是 float 。

使用

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

避免这个问题。

关于Java SWT : Getting original X/Y Coordinates from Scaled Image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37706768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com