Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Grafik / Sound / Multimedia (https://www.delphipraxis.net/21-library-grafik-sound-multimedia/)
-   -   Delphi Koordinatensystem / Gitternetzlinien in TImage (https://www.delphipraxis.net/2630-koordinatensystem-gitternetzlinien-timage.html)

Daniel B 30. Jan 2003 23:31


Koordinatensystem / Gitternetzlinien in TImage
 
Delphi-Quellcode:
procedure TForm1.btn_DrawGridClick(Sender: TObject);
const GridSize : Integer = 20;
var xSteps, ySteps, xIndex, yIndex : Integer;
begin
  If not Image1.Picture.Bitmap.Empty Then
    With Image1.Picture.Bitmap Do
    Begin
      xSteps:= Width div GridSize;
      ySteps:= Height div GridSize;

      With Canvas Do
      Begin

        Pen.Width:= 1;
        Pen.Color:= clSilver;
        Pen.Style:= psSolid;

        For xIndex:= 0 To xSteps Do
          For yIndex:= 0 To ySteps Do
          Begin
            MoveTo( 0, yIndex*GridSize ); LineTo( Width, yIndex*GridSize );
            MoveTo( xIndex*GridSize, 0 ); LineTo( xIndex*GridSize, Height );
          End;
      End;
    End
  Else
    ShowMessage( 'Kein Bild verfügbar.' );
end;
Das Ergebnis ist hier zu sehen!

Von DrDangerous!

Grüsse, Daniel :hi:

Ein Verbesserungsvorschlag von CarstenB:

Zitat:

Man sollte die beiden Zählschleifen trennen, da sonst alles zig mal gezeichnet wird, was merklich auf die Performance gehen dürfte.

Delphi-Quellcode:
For xIndex:= 0 To xSteps Do begin
  MoveTo( xIndex*GridSize, 0 ); LineTo( xIndex*GridSize, Height );
End;
For yIndex:= 0 To ySteps Do Begin
  MoveTo( 0, yIndex*GridSize ); LineTo( Width, yIndex*GridSize );
end;

[edit=Luckie]Verbesserungsvorschlag von CarstenB. Mfg, Luckie[/edit]


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:50 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz