Click here to Skip to main content
15,029,736 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
if my canvas is reflecting some real life measurements like 8 meter by 6 meter and i draw a line on it, how can i calculate the measurement of that line on canvas. i.e if i draw from position x1,y1 to position x2,y2 i measure it and say for sure that it is approximately x length long. Also will it be possible to show the measurement right below the line on runtime too like as soon as i finish the line,its length is automatically be shown at bottom of it. i am using simple canvas with just 1 draw line function with javascript atm.
Posted

1 solution

To convert pixels to real time measurements you first need to know the DPI of your the monitor, means how many dots it have in inch - that's why it called DPI...
Unfortunately for you there is no way to get this info from OS using JavaScript...
   
Comments
mughees ilyas 8-Mar-14 15:37pm
   
well lets just say that my screen is 75 dpi and most screens usually are 75 dpi
and my canvas is 300 by 300
what next
Kornfeld Eliyahu Peter 8-Mar-14 15:51pm
   
I checked all my monitors (there are 3) and all have 120 DPI...
However if you have 300 dots (pixels) it is 4 inches on a 75 DPI monitor, that's about 9.8 cm...
mughees ilyas 8-Mar-14 18:28pm
   
m pretty sure monitors have ppi not dpi actually ._.
anyway ur ans is not helpful atall
Kornfeld Eliyahu Peter 9-Mar-14 0:44am
   
PPI = Pixel Per Inch
DPI = Dot Per Inch
I'm not a native English but pretty sure dot and pixel can used (at least here) as same...
Maybe my answer isn't useful because you try to do something that can't be done... :-)

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