Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Opaciy Problem in Firemonkey (https://www.delphipraxis.net/187167-opaciy-problem-firemonkey.html)

ht47 3. Nov 2015 11:32

Opaciy Problem in Firemonkey
 
Hallo,

ich experimentiere derzeitig ein wenig mit Delphi XE7 und Firemonkey. Ich habe aber ein Problem mit Drawline und der Opacity Einstellung.

Ich benutze eine Form mit einem Button und einer Paintbox. Im OnClick des Buttons nutze ich folgenden Code:

begin
PaintBox1.Canvas.BeginScene;
PaintBox1.Canvas.DrawLine(PointF(10,10),PointF(110 ,10),1);
PaintBox1.Canvas.DrawLine(PointF(110,10),PointF(11 0,110),1);
PaintBox1.Canvas.DrawLine(PointF(110,110),PointF(1 0,110),1);
PaintBox1.Canvas.DrawLine(PointF(10,110),PointF(10 ,10),1);
PaintBox1.EndScene;
end;

Das Zeichnen funktioniert eigentlich problemlos. Nur werden die Linie nicht in vollem schwarz gezeichnet, sondern höchstens in 50 % Deckung. Woran kann das liegen ?

Grüße

Holger

Darlo 3. Nov 2015 11:50

AW: Opaciy Problem in Firemonkey
 
Was für eine
Delphi-Quellcode:
Tickness
hast Du dnen eingestellt? Kann es sein, dass bei
Delphi-Quellcode:
Tickness := 1
das aufgrund von Kantenglättung einfach so wirkt?

Der schöne Günther 3. Nov 2015 11:54

AW: Opaciy Problem in Firemonkey
 
Hallo und Willkommen in den Heiligen Hallen des Wissens und des Wahnsinns :hi:

Der Deckungsgrad ist mit
Delphi-Quellcode:
1.0
schon richtig gewählt. Es liegt an der Dicke des Stifts. Füge nach deinem
Delphi-Quellcode:
BeginScene()
mal die Zeile
Delphi-Quellcode:
PaintBox1.Canvas.StrokeThickness := 0.75;
ein und der Effekt verstärkt sich noch!

Es wäre nämlich zu einfach gewesen auf glatten Koordinaten wie (100 | 0) zu zeichnen, du musst jeweils die halbe Stiftbreite wieder abziehen.

Hier als Beispiel einmal das ständige Abziehen einmal in eine lokale Prozedur "draw" ausgelagert. Im Nachhinein merke ich dass es wohl schlauer gewesen wäre das als Klassenhelfer zu machen :oops:

Delphi-Quellcode:
procedure TForm3.Button1Click(Sender: TObject);
var
   fromPoint:   TPointF;
   toPoint:   TPointF;
   draw:      TProc<TPointF, TPointF>;
begin
   draw :=
      procedure(fromPoint, toPoint: TPointF)
      var
         offset: Single;
      begin
         offset := PaintBox1.Canvas.StrokeThickness / 2.0;
         fromPoint.Offset(-offset, -offset);
         toPoint.Offset(-offset, -offset);
         PaintBox1.Canvas.DrawLine(fromPoint, ToPoint, 1.0);
      end;

   PaintBox1.Canvas.BeginScene();
   try
      fromPoint := TPointF.Create(10, 10);
      toPoint := fromPoint; toPoint.Offset(100, 0);
      draw(fromPoint, toPoint);

      fromPoint.Offset(100, 0); toPoint.Offset(0, 100);
      draw(fromPoint, toPoint);

      fromPoint.Offset(0, 100); toPoint.Offset(-100, 0);
      draw(fromPoint, toPoint);

      fromPoint.Offset(-100, 0); toPoint.Offset(0, -100);
      draw(fromPoint, toPoint);
   finally
      PaintBox1.Canvas.EndScene();
   end;
end;

Rollo62 4. Nov 2015 09:36

AW: Opaciy Problem in Firemonkey
 
Man könnte auch gleich ein Polygon zeichnen wenn mehrere Linien verbunden sind:


Code:
procedure S4Canvas_Polyline_Draw(const Canvas: TCanvas;
                                 const Points: TPolygon;
                                 const AOpacity: Single);
var
  I: Integer;
{$IFNDEF IOS}
  Path: TPathData;
{$ENDIF IOS}

begin

{$IFDEF IOS}

  try
    // BugFix: Must draw the polygon as single-line sequence: TPathData doesn'T work here
    //Update:
    // Das war bei XE8, mit Rx10 noch nicht getestet, vielleicht passt es jetzt.
    // Hat sicher etwas mit SceneScale zu tun ...

    for I := 1 to High(Points) do
    begin
       Canvas.DrawLine(Points[I-1], Points[I], AOpacity );
    end;

  finally

  end;


{$ELSE not IOS}

  Path := TPathData.Create;

  try
    for I := 0 to High(Points) do
    begin
      if I = 0 then
        Path.MoveTo(Points[I])
      else
        Path.LineTo(Points[I]);
    end;

    Canvas.DrawPath(Path, AOpacity);

  finally
    Path.Free;
    Path := nil;
  end;


{$ENDIF not IOS}

end;
Rollo

ht47 7. Nov 2015 01:26

AW: Opaciy Problem in Firemonkey
 
Hallo,

Danke für die Hilfe. Jetzt funktioniert es.

Holger


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:40 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