How to draw in real size to screen and printer lazarus / 39-Graphics ---------------------------------------------------------------------- AL · 2020-11-04 21:20 I am doing my first attempt at graphics and need help. I want to draw a simple shape to the screen with actual size and eventually print it so I can get a template. I am using a paintbox and I can show a line so this is fine. But... whatever I do to calculate the line lenght it always come 2-3 mm longer that it is supposed (when I measure on the screen). I calculate the number of pixels with : trunc( length in mm /25.4 * ScreenDPI) Do I miss something? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject); var  w, h: Integer;    // Width and height of the rectangle  cx, cy: Integer;  // center of the form  lx: integer ; // left x coord  R: TRect;         // record containing the coordinates of the rectangle's left, top, right, bottom corners  ScrnDPI, NutPixel : Integer ;  NutWidth : real ;begin   NutWidth := 50 ;   ScrnDPI := Screen.PixelsPerInch ;   memo1.Append('ScreenDPI ' + ScrnDPI.ToString);    NutPixel := trunc(NutWidth/25.4 * ScrnDPI) ;   memo1.Append('NutPixel ' + NutPixel.ToString);    // Calculate PaintBox center   cx := NutPaintBox.Width div 2;  cy := NutPaintBox.Height div 2;   // Calculate the size of the rectangle  w := NutPaintBox.Width ;//div 2;  h := NutPaintBox.Height;// div 2;   // Calculate the corner points of the rectangle  R.Left := cx - w div 2;  R.Top := cy - h div 2;  R.Right := cx + w div 2;  R.Bottom := cy + h div 2;  with NutPaintBox do begin  // Set the fill color  Canvas.Brush.Color := clgray;  Canvas.Brush.Style := bsSolid;   // Set the border color  Canvas.Pen.Color := clBlue;  Canvas.Pen.Width := 2;  Canvas.Pen.Style := psSolid;   // Draw the rectangle  Canvas.Rectangle(R);   // Draw a line  Canvas.Pen.Width := 1;  // left coordinate to have a centered line  lx :=  (cx - NutPixel div 2) ;  memo1.Append('lx ' + lx.ToString);   Canvas.Line( lx,cy,(lx + NutPixel),cy); end;end; ---------------------------------------------------------------------- winni · 2020-11-04 21:40 Hi! If you work with integers, statistically on every second DIV you loose one pixel. Use the BGRAbitmap which can calculate subpixels with single values. BGRAbitmap is available in the Online Packet Manager. Winni ---------------------------------------------------------------------- AL · 2020-11-04 21:48 Thank you, I will look in that. However, I do not loose pixels, my line is longer so I have more! ---------------------------------------------------------------------- howardpc · 2020-11-04 21:50 Additionally, the values reported for your screen's X/Y pixels per inch ratios -- depending on your actual hardware and its drivers -- may be approximate rather than exact; and in any case are defined as integral quantities with no provision for sub-pixels. On large screens this gives quite a margin of error. Hence why some CAD and other design software that needs high precision for screen representation may get each user to run a calibration routine when the program is first used to customise it for the actual hardware it is running on. ---------------------------------------------------------------------- VTwin · 2020-11-04 23:00 Measurements on the screen are likely to be variable. When you actually save it to a jpeg, png, or tiff, you should be able to set the dpi and get very good results when printing. ---------------------------------------------------------------------- winni · 2020-11-05 00:02 Hi! Where is your Monitor made??? China??? 1 metre is equal to 30 chinese inch, or 39.370078740157 inches. From: https://www.convertunits.com/from/chinese+inch/to/inches Winni PS.: I think you should care more about howardpc and VTwin answers ---------------------------------------------------------------------- circular · 2020-11-05 04:21 Screen DPI values can even be completely off. Their initial value is always 96 whatever the screen and when you make elements bigger in Windows or Linux, you are freely changing the value of the DPI. If you want to know, you need to calibrate it: draw a line that is supposed to be 10 cm, ask the person to measure it and from there determine the real DPI.