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
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.