# I cannot adjust the physical drawing scale on the canvas and phone screen (1:1)

I am trying to create an application to draw a polygon with a metric unit of measurement (cm). I want the drawing to be at a drawing scale of 1:1, as if the phone screen were paper, and when I put the measuring ruler on it, it gives the same length. I used ( GetMetric Extension ) and applied the following equation LENGTH ( Centimeter ) = 2.54 * Length ( Pixel ) / DPI , The length was converted from pixels to cm on the Can, but when I measure it with a ruler, it does not give the same value as in the canvas

.

See

from

On my device, where I happen to know that the dpi is `2.5`, this seems to work:

4 is 4cm, which you draw as 256 pixels (so you can see that 1cm = 64 pixels). 64 seems to be the magic number for me.

I tried what you said but unfortunately it didn't work

I used it but it didn't work. It seems there is a missing parameter. I don't know what it is

For me the formula is:

``````cmLength = pixelsLength/(dpi*25.4)

or the other way

pixelsLength = cmLength*dpi*25.4
``````

It gave illogical results

You don't include the pixelsLength?
Is your dpi also 2.5 ?

You should work with the cmLength in order to get the pixelsLength needed to be drawn on the canvas.

To test, just draw a line.

my aia file attached please check

I want a value that can be used on any device, not just my device, to give a real measure that can be measured with a ruler on the screen

thanks
trialarea.aia (1.7 MB)

This attempt did not succeed either. There is still something missing in the equation

This draws correct lines with lengths of 10mm.

pixels.aia (7.5 KB)

2 Likes

Your method succeeded in drawing only vertical and horizontal lines to scale, but it did not succeed in drawing diagonal lines

For diagonal lines, use the math of the Pythagorean theorem. My method turns mm into points on the canvas, the rest of the application is pure mathematics depending on what you want to use it for.

its a good idea if i want to input length but in my case as shown in the attached aia there is no inputs there is skecth by pixel unit i want the text behind to be true if i use scale 1:1 , i cant apply your idea in my app

If I choose a 1:1 scale, how many cm should the square be on the screen and what value should it be above the line? I think the sample app is missing an image with a grid. But I don't know if it's a better idea to draw a grid instead of using images...

It makes perfect sense to draw the grid, the grid image will not scale: you cannot eat your cake and have it, measurements that match your analog external ruler AND fit with the displayed grid image.

An example with blocks for drawing grids below, may need modifying for you needs

The problem is the canvas component, which is scaled to a maximum width of 320 (regardless of the number of pixels or screen density), but the height is worse because it depends on the device's screen proportions. While the width density can be calculated by setting the Canvas width to fill parent and it is always 320px (you can set this number of px as a constant width), obtaining the height density is worse. Although we can use the screen height from the Screen1 drawer, it does not return the height of the entire screen, like the getMetrics extension, so we cannot calculate the density for Canvas here. We will therefore assume that the density for the height will be the same as the density for the width. Then we can calculate the density as 320/widthMm.

trialarea2.aia (1.6 MB)

it depends, on my phone it's 360.