AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia FMX bunte Polygone zeichnen
Thema durchsuchen
Ansicht
Themen-Optionen

FMX bunte Polygone zeichnen

Ein Thema von bernhard_LA · begonnen am 18. Aug 2020 · letzter Beitrag vom 18. Aug 2020
Antwort Antwort
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.123 Beiträge
 
Delphi 11 Alexandria
 
#1

FMX bunte Polygone zeichnen

  Alt 18. Aug 2020, 08:23
scheitere aktuell dabei jetzt bunte Polygone zu zeichnen


hier der Demo code :


Delphi-Quellcode:
procedure TForm1.btn_draw_PolygonClick(Sender: TObject);
var
  p1, p2, p3, p4, p5: TPointF;
  MyPolygon: TPolygon;
  I: Integer;
  Brush: TStrokeBrush;
begin


  for I :=1 to 10 do
  begin
  Brush := TStrokeBrush.Create(TBrushKind.Solid, randomColor);
  Brush.Thickness := 2;
  // sets the points that define the polygon
  p1 := TPointF.Create(200+ Random(50), 220 + Random(50) );
  p2 := TPointF.Create(250+ Random(50), 360+ Random(50));
  p3 := TPointF.Create(280+ Random(50), 260+ Random(50));
  p4 := TPointF.Create(200+ Random(50), 180+ Random(50));
  p5 := TPointF.Create(100+ Random(50), 160+ Random(50));
  // creates the polygon
  SetLength(MyPolygon, 5);
  MyPolygon[0] := p1;
  MyPolygon[1] := p2;
  MyPolygon[2] := p3;
  MyPolygon[3] := p4;
  MyPolygon[4] := p5;

  // localBMP.Canvas.Stroke := Brush; geht nicht weil read only property ......

  localBMP.Canvas.BeginScene;
  // draws the polygon on the canvas
  localBMP.Canvas.DrawPolygon(MyPolygon, 50) ;
  localBMP.Canvas.EndScene;
  // updates the bitmap
  // Image1.Bitmap.BitmapChanged;

  LoadBMP2GUI(nil);

  Brush.Free;
  end;
end;

ich kann den Brush nicht an meine Bitmap übergeben , und einen Aufruf incl. Brush gibt es für Canvas.DrawPolygon nicht
Miniaturansicht angehängter Grafiken
random_polygon.jpg  

Geändert von bernhard_LA (18. Aug 2020 um 08:27 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Sherlock
Sherlock

Registriert seit: 10. Jan 2006
Ort: Offenbach
3.763 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: FMX bunte Polygone zeichnen

  Alt 18. Aug 2020, 09:01
FMX.TCanvas.Stroke.Kind muss auch gesetzt werden, meine ich.

Sherlock
Oliver
Geändert von Sherlock (Morgen um 16:78 Uhr) Grund: Weil ich es kann
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
3.908 Beiträge
 
Delphi 12 Athens
 
#3

AW: FMX bunte Polygone zeichnen

  Alt 18. Aug 2020, 10:02
DocWiki ist gerade down (mal wieder).
https://www.ideasawakened.com/post/s...i-applications
http://delphi.org/2019/02/delphis-bi...ittle-svg-fun/

Probier das doch mal mit TPath, in PathData da kann man direkt beliebige SVG-ähnliche Pfade eingeben.
  Mit Zitat antworten Zitat
philipp.hofmann

Registriert seit: 21. Mär 2012
Ort: Hannover
859 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: FMX bunte Polygone zeichnen

  Alt 18. Aug 2020, 13:52
Ich mache es mit folgendem Code (ist aber eine Vereinfachung, da meine Polygon-Form relativ fix ist):

Delphi-Quellcode:
unit SimplePolygon;

interface

uses
  System.Classes, System.Types, FMX.Objects, System.Math.Vectors;

type
  TSimplePolygon = class(TShape)
  private
    FPoints: TPolygon;
  protected
    procedure Paint; override;
  public
    heightEnd:single;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
  end;

procedure Register;

implementation

uses MyLog;

procedure Register;
begin
  RegisterComponents('Shapes', [TSimplePolygon]);
end;

{ TSimpleTriangle }

constructor TSimplePolygon.Create(AOwner: TComponent);
begin
  inherited;
  SetLength(FPoints, 5);
end;

destructor TSimplePolygon.Destroy;
begin
  Finalize(FPoints);
  inherited;
end;

procedure TSimplePolygon.Paint;
var
  R: TRectF;
begin
  R := GetShapeRect;
  FPoints[0] := PointF(R.Left, R.Bottom);
  FPoints[1] := PointF(R.Left, R.Top);
  FPoints[2] := PointF(R.Right, R.Top-(heightEnd-height));
  FPoints[3] := PointF(R.Right, R.Bottom);
  FPoints[4] := PointF(R.Left, R.Bottom);
  Canvas.Fill.Assign(Self.Fill);
  Canvas.FillPolygon(FPoints, AbsoluteOpacity);
  Canvas.DrawPolygon(FPoints, AbsoluteOpacity);
end;

end.
Delphi-Quellcode:
            polygon:=TSimplePolygon.Create(self);
            polygon.Parent:=myRExercise;
            polygon.beginUpdate;
            polygon.Name:='RECT_'+IntToStr(i)+'_'+IntToStr(j)+'_'+IntToStr(k);
            polygon.OnClick:=btRectClick;
            polygon.Fill.Color:=myExercise.sequenceList[i].legList[k].getLegLevelColor();
            polygon.Stroke.Dash:=TStrokeDash.Solid;
            polygon.Stroke.Color:=TAlphaColors.Black;
            polygon.Stroke.Thickness:=1;
            polygon.Width:=width;
            polygon.Height:=height;
            polygon.HeightEnd:=heightEnd;
            polygon.Position.X:=lastX;
            polygon.Position.Y:=myRExercise.Height-polygon.Height;
            polygon.EndUpdate;
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:35 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz