DrawLine();
DrawLines();
DrawArc();
DrawBezIEr();
DrawBezIErs();
DrawRectangle();
DrawRectangles();
DrawEllipse();
DrawPIE();
DrawPolygon();
DrawCurve();
DrawClosedCurve();
FillRectangle();
FillRectangles();
FillPolygon();
FillEllipse();
FillPIE();
FillClosedCurve();
DrawLines、DrawPolygon、FillPolygon 測試圖:
DrawLines、DrawPolygon、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、FillRectangles 測試圖:
DrawRectangles、FillRectangles 測試代碼:
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、FillPIE 測試圖:
DrawArc、DrawPie、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、FillClosedCurve 測試圖:
查看原圖(大圖)
DrawCurve、DrawClosedCurve、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;
DrawBezIEr 測試圖:
DrawBezIEr 測試代碼:
uses GdiPlus;
//一條 BezIEr 線需要四個點: 兩個端點、兩個控制點
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.DrawBezIEr(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;
//把一條當作多條畫(DrawBezIErs), 結果同上
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 測試圖:
DrawBezIErs 測試代碼:
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
);
//兩條 Bezier 線需要 7 個點, 而不是 8 個; 因為 Bezier1 的終點即是 BezIEr2 的起點;
//多條 BezIEr 線需要的點數 = 3 * 線數 + 1;
//數組 ID 能被 3 整除的點是端點, 其他是控制點
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;
end;