快点看我有什么!!我有一个定义的屏幕尺寸(5.5英寸)和分辨率(500px宽和350px高),我有这个屏幕上某些位置(x,y)的坐标。
我将拥有什么!!我将有新的屏幕尺寸(8.2英寸)和分辨率(1020px宽和730px高)的规格。
我需要计算/外推/查找什么?我需要用新的分辨率在新的屏幕尺寸上找到相同的x,y位置。我需要一个通用的解决方案,可以在任何屏幕尺寸或分辨率。
有没有人能帮我。
发布于 2016-03-17 19:23:55
屏幕大小可能并不重要,我们所关心的是分辨率。
给定旧的坐标,我们可以除以旧的分辨率,然后乘以新的分辨率。
这给出了一个在相同比例位置的坐标。(在调整图像大小时,类似于图像上点的位置。)
伪代码示例:
function newCoords(oldCoords) {
newCoords.x = oldCoords.x / oldResolution.x * newResolution.x;
newCoords.y = oldCoords.y / oldResolution.y * newResolution.y;
return newCoords;
}发布于 2017-03-01 01:51:45
public static Point GetRelativeCoordinates(Point absoluteCoordinates)
{
double x, y;
Point newCoords = new Point();
// if theese are not doubles it truncates to zero .
x = absoluteCoordinates.X;
y = absoluteCoordinates.Y;
newCoords.X = Convert.ToInt16( x / 1920 * Screen.PrimaryScreen.Bounds.Width);
newCoords.Y = Convert.ToInt16( y / 1080 * Screen.PrimaryScreen.Bounds.Height);
return newCoords;
}https://stackoverflow.com/questions/32755825
复制相似问题