3

Quickly what I have !! I have a defined screen size (5.5 inches) and resolution (500 px width and 350 px height) and I have co-ordinates of certain location (x, y) on this screen.

What I will have !! I will have the specifications of new screen size (8.2 inches) and resolution (1020 px width and 730 px height).

What I need to calculate/extrapolate/find ? I need to find the same x,y location on the new screen size with the new resolution. And I need a generic solution which could work on any screen size or resolution.

Can anyone please help me with this.

techDiscussion
  • 89
  • 3
  • 12

2 Answers2

6

Screen size probably doesn't matter, all we care about is the resolution.

Given the old coordinates, we can divide by the old resolution, and multiply by the new resolution.

This give a coordinate that is in the same proportional location. (Similar to the location of a dot on an image, as you resize it.)

Example pseudocode:

function newCoords(oldCoords) {
    newCoords.x = oldCoords.x / oldResolution.x * newResolution.x;
    newCoords.y = oldCoords.y / oldResolution.y * newResolution.y;
    return newCoords;
}
  • 1
    This is a great answer and really helped me sort out a similar issue I was WAY over thinking with pre calculating ratios/scales and all sorts of nonsense. – David Burford Jun 12 '18 at 12:44
1
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;
   }
Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
Felipe
  • 11
  • 1