Einzelnen Beitrag anzeigen

Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.429 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: Timage Rect und Canvas Position

  Alt 6. Nov 2013, 09:10
Ungetestet:
Delphi-Quellcode:
{ImgLevel0}
dx0 := ImgLevel0.Picture.Bitmap.Width;
dy0 := ImgLevel0.Picture.Bitmap.Height;
dx1 := ImgLevel0.ClientWidth;
dy1 := ImgLevel0.ClientHeight;

{Den tatsächlichen Zoomfaktor bestimmen.}
zx := dx1/dx0;
zy := dy1/dy0;
z := IfThen(zx < zy, zx, zy);

{Die Größe der Abbildung auf dem Bildschirm.}
dx := Round(z * dx0);
dy := Round(z * dy0);

{Die Position der Abbildung auf dem Image.}
p0.x := (dx1 - dx) div 2;
p0.y := (dy1 - dy) div 2;

{Umrechnung in Bildschirmkoordinaten}
p0 := ImgLevel0.ClientToScreen(p0);

{ImgLevel1}
p1 := ImgLevel1.ClientRect.TopLeft;
dx := ImgLevel1.ClientWidth;
dy := ImgLevel1.ClientHeight;

{Umrechnung in Bildschirmkoordinaten}
p1 := ImgLevel1.ClientToScreen(p1);

{p0 wird zum Koordinatenursprung(0,0) für p1}
p1.x := p1.x - p0.x;
p1.y := p1.y - p0.y;

{Zoom von ImgLevel1 auf ImgLevel0.Picture.Bitmap}
p1.x := Round(p1.x / z);
p1.y := Round(p1.y / z);
dx := Round(dx / z);
dy := Round(dy / z);

{Das Rechteck für die Ausgabe.}
savepic.Picture.Bitmap.Canvas.Rect(p1.x, p1.y, p1.x + dx, p1.y + dy);

Geändert von Blup ( 6. Nov 2013 um 11:34 Uhr)
  Mit Zitat antworten Zitat