Click here to Skip to main content
15,115,261 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I've published my wpf project to several users.
In my project - a user can place the mouse on a canvas and I save the exact point in pixels(x, y) in my database.

I've noticed that after a user that saved several points through his computer (which set to 113DPI), when I tried to see his points it were in a completely different places (my computer is set to 96DPI which is the standard as far a I know).

can you suggest a way, a calculation to change all the points he saved so it will fit the rest of the computers?

for example
name position_X position_Y
point_001 2505 1749

I hope that you'll understand what I mean.

thanx.
Posted
Comments
Richard MacCutchan 20-Jul-14 7:21am
   
You need to do a transform, by converting the points from their original values to the same relative positions on the new scale.
danait25 20-Jul-14 7:35am
   
Well that's what I'm trying to do- is there an equation for that?
How do I know where is the x position: 2505 pxl in 96dpi?
Richard MacCutchan 20-Jul-14 8:07am
   
It depends whether your position is relative to the screen (absolute co-ordinate) or to the Window of your application. In either case the formula is simply divide by the DPI of the screen that it is on and multiply by 96.

1 solution

The formula is simple:
target_x = source_x * target_dpi / source_dpi;
..
   
Comments
danait25 21-Jul-14 3:23am
   
thanks. I tried that ofcourse but from some reason it's not working good.
I'll try again, maybe I did something wrong.
CPallini 21-Jul-14 3:26am
   
Could you please give us some details?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900