Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.167 Beiträge
 
Delphi 12 Athens
 
#9

Re: Pixel in Millimiter umrechnen mit dieser Funktion ?

  Alt 5. Feb 2009, 09:47
ist der DPI-Wert für deinen Monitor eigentlich richtig eingestellt?
(nicht daß da nur irgendwo 'ne falsche Angabe steht)

ich frag mich auch, was du mit myscreenWidth und myscreenHeight anstellst.
Delphi-Quellcode:
procedure TForm1.PixelsPerMM(canvas: TCanvas; var x, y: Extended);
var
    H:HDC;
    hres,vres,
    hsiz,vsiz:integer;
begin
    H:=canvas.handle;
    hres := GetDeviceCaps(H,HORZRES) ; {display width in pixels}
    vres := GetDeviceCaps(H,VERTRES) ; {display height in pixels}
    hsiz := GetDeviceCaps(H,HORZSIZE) ; {display width in mm}
    vsiz := GetDeviceCaps(H,VERTSIZE) ; {display height in mm}
    x := hres/hsiz;
    y := vres/vsiz;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  X, Y: Extended;
begin
  PixelsPerMM(Form1.Canvas, X, Y);
  Edit1.Text := FloatToStr(X); { the x value holds the pixels per mm horizontally }
  Edit2.Text := FloatToStr(Y); { the y value holds the pixels per mm vertically }

  Edit3.Text := FloatToStr(screen.Width * X);
  Edit4.Text := FloatToStr(screen.Height * Y);
end;

und falls es dir noch nicht aufgefallen ist,
HORZSIZE und VERTSIZE geben bereits die größe in Millimetern an,
wozu willst du also noch rechnen?

(Pixel / 1 mm) * Pixel = mmFürAllePixel
Delphi-Quellcode:
// für jeden Monitor einzeln
var h: hDC;
  hsiz, vsiz: Integer;
begin
  // i = Index des Monitors
  // 0 >= i < Screen.MonitorCount

  h := GetDC(Screen.Monitors[i].Handle);
  hsiz := GetDeviceCaps(h, HORZSIZE);
  vsiz := GetDeviceCaps(h, VERTSIZE);
  ReleaseDC(Screen.Monitors[i].Handle, h);

  Edit1.Text := FloatToStr(hsiz) + 'mm';
  Edit2.Text := FloatToStr(vsiz) + 'mm';
end;


// für den Desktop
var h: hDC;
  hsiz, vsiz: Integer;
begin
  h := GetDC(GetDesktopWindow);
  hsiz := GetDeviceCaps(h, HORZSIZE);
  vsiz := GetDeviceCaps(h, VERTSIZE);
  ReleaseDC(GetDesktopWindow, h);

  Edit1.Text := FloatToStr(hsiz) + 'mm';
  Edit2.Text := FloatToStr(vsiz) + 'mm';
end;
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat