2

In an application, let suppose we have an image of a car onto which we have mark a damage point. We can mark this point anywhere of the image as shown below.

Image 1:

Suppose we have marked this point on a device of screen size “5 inches” and then we calculated the coordinates of this point and sent it to the server. Now the user is using another device of screen size “8 inches”. User wants to see those marked points in his new device. But he is not able to see the appropriate position of the points after fetching the actual value from the server.

Image 2:

Hadi
  • 36,233
  • 13
  • 65
  • 124
FreakCoder
  • 21
  • 2
  • instead of a coordinates just upload the whole image with damage point to your server. – Rahul Sharma Mar 31 '17 at 05:10
  • 1
    @RahulSharma sending image to the server is not an actual solution. – FreakCoder Mar 31 '17 at 05:15
  • You can always calculate the coordinates as a proportion of the screen size in both the x and y directions. These proportions can be uploaded to the server in the form of a simple array. – Ethan Mar 31 '17 at 05:32
  • @Ethan Thanks for your response. Can you give me an example of calculating the coordinates as a proportion of the screen size in both the x and y directions. – FreakCoder Mar 31 '17 at 09:46

2 Answers2

3

I think the coordinates depend on the device's screen dpi. Assume your server always store the coordinates in mdpi. Then you should get the correct coordinates at device at different dpi like this:

DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

float screenAdjust = (float) dm.densityDpi / 160f;


int x = (int) (x_value_from_server) * screenAdjust);
int y = (int) (y_value_from_server) * screenAdjust);
mobile app Beginner
  • 1,651
  • 3
  • 26
  • 40
0

Get the height and width of the screen

    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int height = displayMetrics.heightPixels;
    int width = displayMetrics.widthPixels;

Then calculate the coordinates of the image, I assume you are currently doing this in the form of an [x,y] array

Then simply find the ratio across all screen sizes by doing:

float x_ratio = coordinatesArray[0]/width
float y_ratio = coordinatesArray[1]/height

This will result in something along the lines of 0.25 and 0.34 (or something like that depending on the screen size)

You then simply create an array including these two floats and pass this along to the server.

Ethan
  • 1,905
  • 2
  • 21
  • 50