Einzelnen Beitrag anzeigen

Jakson

Registriert seit: 10. Mär 2006
34 Beiträge
 
#1

Graphics32 Zeichne Polygon mit größerer Linienbreite

  Alt 20. Feb 2015, 09:48
Nachdem ich mich durch etliche Internet Seiten und Foren gekämpft habe um herauszufinden wie man mit Graphics32 eine Linie zeichnen kann die nicht nur einen Pixel breit ist will ich euch nun das Ergebnis präsentieren.

Standardmäßig unterstützt Graphics32 keine andere Linienbreite als 1!
Benötigt man trotzdem eine breitere Linie so muss man mehrere nebeneinander zeichnen oder die Klasse TPolygon32 bemühen und die gewünschte Linie damit zu verbreitern.

Um die Arbeit zu erleichtern hab ich dafür eine abgeleitete klasse erstellt.
Delphi-Quellcode:
type
 TPolygon32_LineWidth = class(TPolygon32)
 public
   procedure DrawLineXS(Bitmap:TCustomBitmap32;LineWidth:Byte;Color:TColor32;Closed:Boolean);
   procedure DrawLineXSP(Bitmap:TCustomBitmap32;LineWidth:Byte;Closed:Boolean);
 end;

{ TPolygon32_LineWidth }

procedure TPolygon32_LineWidth.DrawLineXS(Bitmap:TCustomBitmap32;LineWidth:Byte;Color:TColor32;Closed:Boolean);
var PolygonOutl,
    PolygonGrow : TPolygon32;
begin
 if LineWidth <= 1
  then PolyPolylineXS(Bitmap,Points,Color,Closed)
  else begin
   Self.Closed := Closed;
   Antialiased := True;
   PolygonOutl := Outline;
   PolygonGrow := PolygonOutl.Grow(Fixed(LineWidth/2));
   try
    PolygonGrow.FillMode := pfWinding;
    PolygonGrow.DrawFill(Bitmap,Color);
   finally
    PolygonGrow.Free;
    PolygonOutl.Free;
   end;
  end;
end;

procedure TPolygon32_LineWidth.DrawLineXSP(Bitmap:TCustomBitmap32;LineWidth:Byte;Closed:Boolean);
var Count1,
    Count2,
    NextNr,
    CountLine,
    Multy,
    DeltaX,
    DeltaY : Integer;
    Strippl_Start : Extended;
begin
 if LineWidth <= 1
  then PolyPolylineXSP(Bitmap,Points,Closed)
  else begin
   Self.Closed := Closed;
   BuildNormals;
   if Assigned(Points) then
    for Count1 := 0 to High(Points) do
     begin
      if Length(Points[Count1]) > 1 then
       for Count2 := 0 to High(Points[Count1]) do
        begin
         NextNr := Count2+1;
         if Count2 >= High(Points[Count1]) then
          if Closed
           then NextNr := 0
           else Break;
           
         Strippl_Start := Bitmap.StippleCounter;
         Bitmap.LineXSP(Points[Count1][Count2].X,Points[Count1][Count2].Y,Points[Count1][NextNr].X,Points[Count1][NextNr].Y);

         for CountLine := 0 to LineWidth-2 do
          begin
           Bitmap.StippleCounter := Strippl_Start;
           if Odd(CountLine)
            then Multy := (CountLine DIV 2)+1
            else Multy := (CountLine DIV 2)+1 * -1;

           DeltaX := Normals[Count1][Count2].X * Multy;
           DeltaY := Normals[Count1][Count2].Y * Multy;
           Bitmap.LineXSP(Points[Count1][Count2].X+DeltaX,Points[Count1][Count2].Y+DeltaY,Points[Count1][NextNr].X+DeltaX,Points[Count1][NextNr].Y+DeltaY);
          end;
        end;
     end;
  end;
end;
  Mit Zitat antworten Zitat