Gdiplus [33]: Basic Drawing and filling command

Source: Internet
Author: User
DrawLine();DrawLines();DrawArc();DrawBezier();DrawBeziers();DrawRectangle();DrawRectangles();DrawEllipse();DrawPie();DrawPolygon();DrawCurve();DrawClosedCurve();FillRectangle();FillRectangles();FillPolygon();FillEllipse();FillPie();FillClosedCurve();
 

Drawlines, drawpolygon, and fillpolygon test charts:


Test code for drawlines, drawpolygon, and fillpolygon:
uses GdiPlus;procedure TForm1.FormPaint(Sender: TObject);const  Pts: array[0..3] of TGPPointF = ((X:20; Y:80), (X:60; Y:20), (X:100; Y:80), (X:60; Y:140));var  Graphics: IGPGraphics;  Pen: IGPPen;  Brush: IGPSolidBrush;  Font: IGPFont;  i: Integer;begin  Graphics := TGPGraphics.Create(Handle);  Pen := TGPPen.Create($FFFF0000, 2);  Brush := TGPSolidBrush.Create($FF000000);  Font := TGPFont.Create(Canvas.Handle);  Graphics.DrawLines(Pen, Pts);  for i := 0 to Length(Pts) - 1 do Graphics.DrawString(IntToStr(i), Font, Pts[i], Brush);  Graphics.TranslateTransform(110, 0);  Graphics.DrawPolygon(Pen, Pts);  Brush.Color := $FFFFFF00;  Graphics.TranslateTransform(110, 0);  Graphics.FillPolygon(Brush, Pts);  Graphics.TranslateTransform(110, 0);  Graphics.FillPolygon(Brush, Pts);  Graphics.DrawPolygon(Pen, Pts);end;
 

Drawrectangles and fillrectangles test charts:


Drawrectangles and fillrectangles test code:
uses GdiPlus;procedure TForm1.FormPaint(Sender: TObject);var  Graphics: IGPGraphics;  Pen: IGPPen;  Brush: IGPSolidBrush;  Rects: array[0..2] of TGPRect;begin  Rects[0].Initialize(40, 20, 20, 20);  Rects[1].Initialize(30, 40, 40, 40);  Rects[2].Initialize(10, 80, 80, 80);  Graphics := TGPGraphics.Create(Handle);  Pen := TGPPen.Create($FFFF0000, 2);  Brush := TGPSolidBrush.Create($FFC0C0C0);  Graphics.DrawRectangles(Pen, Rects);  Graphics.TranslateTransform(110, 0);  Graphics.FillRectangles(Brush, Rects);  Graphics.TranslateTransform(110, 0);  Graphics.FillRectangles(Brush, Rects);  Graphics.DrawRectangles(Pen, Rects);end;
 

Drawarc, drawpie, and fillpie test charts:


Test code for drawarc, drawpie, and fillpie:
uses GdiPlus;procedure TForm1.FormPaint(Sender: TObject);var  Graphics: IGPGraphics;  Pen: IGPPen;  Brush: IGPSolidBrush;  Rect: TGPRect;begin  Rect.Initialize(15, 15, 160, 80);  Graphics := TGPGraphics.Create(Handle);  Pen := TGPPen.Create($FFFF0000, 2);  Brush := TGPSolidBrush.Create($FFB0C4DE);  Graphics.FillEllipse(Brush, Rect);  Graphics.DrawArc(Pen, Rect, 0, 45);  Graphics.TranslateTransform(0, Rect.Y + Rect.Height);  Graphics.FillEllipse(Brush, Rect);  Graphics.DrawPie(Pen, Rect, 0, 45);  Graphics.TranslateTransform(0, Rect.Y + Rect.Height);  Graphics.FillEllipse(Brush, Rect);  Brush.Color := $FFFFD700;  Graphics.FillPie(Brush, Rect, 0, 45);  Graphics.TranslateTransform(0, Rect.Y + Rect.Height);  Brush.Color := $FFB0C4DE;  Graphics.FillEllipse(Brush, Rect);  Brush.Color := $FFFFD700;  Graphics.FillPie(Brush, Rect, 0, 45);  Graphics.DrawPie(Pen, Rect, 0, 45);end;
 

Drawcurve, drawclosedcurve, and fillclosedcurve test charts:


Test code for drawcurve, drawclosedcurve, and fillclosedcurve:
uses GdiPlus;const  Pts: array [0..5] of TGPPoint = (    (X: 10;  Y:  40),    (X: 100; Y:  60),    (X: 150; Y:  20),    (X: 130; Y: 100),    (X: 70;  Y:  80),    (X: 30;  Y: 140));procedure TForm1.FormPaint(Sender: TObject);const  m = 180;  n = 160;var  Graphics: IGPGraphics;  Pen: IGPPen;  BrushBak, Brush: IGPBrush;begin  Graphics := TGPGraphics.Create(Handle);  Pen := TGPPen.Create($FFFF0000, 2);  BrushBak := TGPSolidBrush.Create($FFD8BFD8);  Brush := TGPSolidBrush.Create($FFFFD700);  with Graphics do  begin    FillPolygon(BrushBak, Pts);    DrawCurve(Pen, Pts);    TranslateTransform(m, 0);    FillPolygon(BrushBak, Pts);    DrawCurve(Pen, Pts, 1.5);    TranslateTransform(m, 0);    FillPolygon(BrushBak, Pts);    DrawCurve(Pen, Pts, 0.5);    TranslateTransform(m, 0);    FillPolygon(BrushBak, Pts);    DrawCurve(Pen, Pts, 0);    //    TranslateTransform(-Transform.OffsetX, 150);    FillPolygon(BrushBak, Pts);    DrawClosedCurve(Pen, Pts);    TranslateTransform(m, 0);    FillPolygon(BrushBak, Pts);    DrawClosedCurve(Pen, Pts, 1.5);    TranslateTransform(m, 0);    FillPolygon(BrushBak, Pts);    DrawClosedCurve(Pen, Pts, 0.5);    TranslateTransform(m, 0);    FillPolygon(BrushBak, Pts);    DrawClosedCurve(Pen, Pts, 0);    //    TranslateTransform(-Transform.OffsetX, n);    FillPolygon(BrushBak, Pts);    FillClosedCurve(Brush, Pts);    DrawClosedCurve(Pen, Pts);    TranslateTransform(m, 0);    FillPolygon(BrushBak, Pts);    FillClosedCurve(Brush, Pts, FillModeAlternate, 1.5);    DrawClosedCurve(Pen, Pts, 1.5);    TranslateTransform(m, 0);    FillPolygon(BrushBak, Pts);    FillClosedCurve(Brush, Pts, FillModeAlternate, 0.5);    DrawClosedCurve(Pen, Pts, 0.5);    TranslateTransform(m, 0);    FillPolygon(BrushBak, Pts);    FillClosedCurve(Brush, Pts, FillModeAlternate, 0);    DrawClosedCurve(Pen, Pts, 0);  end;end;
 

Drawing:


Drawbezr test code:
Uses gdiplus; // four points are required for a bezr line: two endpoints and two Control Points procedure tform1.formpaint (Sender: tobject); var graphics: igpgraphics; pen: igppen; P1, C1, C2, p2: tgppoint; begin p1.initialize (30,100); c1.initialize (120, 10); c2.initialize (170,150); p2.initialize (220, 80); graphics: = tgpgraphics. create (handle); pen: = tgppen. create ($ ff0000ff, 2); graphics. drawbezr (pen, P1, C1, C2, P2); pen. width: = 1; pen. color: = $ ffff0000; graphics. drawrectangle (pen, P1.X-3, P1.Y-3, 6, 6); graphics. drawrectangle (pen, P2.X-3, P2.Y-3, 6, 6); graphics. drawellipse (pen, C1.X-3, C1.Y-3, 6, 6); graphics. drawellipse (pen, C2.X-3, C2.Y-3, 6, 6); pen. color: = $ ffc0c0c0; graphics. drawline (pen, P1, C1); graphics. drawline (pen, P2, C2); end; // use a row as multiple paintings (drawbeziers). The result is the same as procedure tform1.formpaint (Sender: tobject); var graphics: igpgraphics; pen: igppen; PTS: array [0 .. 3] of tgppoint; begin PTS [0]. initialize (30,100); PTS [1]. initialize (120, 10); PTS [2]. initialize (170,150); PTS [3]. initialize (220, 80); graphics: = tgpgraphics. create (handle); pen: = tgppen. create ($ ff0000ff, 2); graphics. drawbeziers (pen, PTS); pen. width: = 1; pen. color: = $ ffff0000; graphics. drawrectangle (pen, PTS [0]. x-3, PTS [0]. y-3 (6, 6); graphics. drawrectangle (pen, PTS [3]. x-3, PTS [3]. y-3 (6, 6); graphics. drawellipse (pen, PTS [1]. x-3, PTS [1]. y-3 (6, 6); graphics. drawellipse (pen, PTS [2]. x-3, PTS [2]. y-3, 6, 6); pen. color: = $ ffc0c0c0; graphics. drawline (pen, PTS [0], PTS [1]); graphics. drawline (pen, PTS [3], PTS [2]); end;
 

Drawbeziers test diagram:


Drawbeziers test code:
Uses gdiplus; const PTS: array [0 .. 6] of tgppoint = (X: 24; Y: 32), // pt1 (X: 16; Y: 88), // C1 (X: 36; Y: 132), // C2 (X: 120; Y: 20), // pt2 (X: 180; Y: 150), // C3 (X: 210; Y: 90), // C4 (X: 210; Y: 20) // pt3); // seven points are required for the two besuppliers, instead of eight; because the end point of bezier1 is the start point of bezier2; // The number of points required for multiple bezierlines = 3 * number of lines + 1; // The point whose array ID can be divisible by 3 is the endpoint, others are Control Points procedure tform1.formpaint (Sender: tobject); var graphics: igpgraphics; pen: igppen; brush: igpbrush; rect: tgprect; I: integer; begin graphics: = tgpgraphics. create (handle); pen: = tgppen. create ($ ffff0000, 2); brush: = tgpsolidbrush. create ($ 800000ff); graphics. drawbeziers (pen, PTS); for I: = 0 to length (PTS)-1 do begin rect. initialize (PTS [I]. x-4, PTS [I]. y-4, 8, 8); If I mod 3 = 0 then graphics. fillrectangle (brush, rect) else graphics. fillellipse (brush, rect); end;
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.