Delphi Direct2D example
提示:这里可以添加技术概要
核心源码
procedure TForm1.Button1Click(Sender: TObject);
var
LD2DCanvas: TDirect2DCanvas;
begin
// Turn off mouse drawing if on
CheckBox1.Checked := false;
if TDirect2DCanvas.Supported then
begin
LD2DCanvas := TDirect2DCanvas.Create(Canvas, ClientRect);
with LD2DCanvas do
try
RenderTarget.BeginDraw;
Pen.Width := 1;
Pen.Color := clGreen;
RenderTarget.Clear(D2D1ColorF(1.0, 1.0, 1.0, 1.0));
RenderTarget.SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
// First Line
DrawLine(D2D1PointF(100.5, 100.5), D2D1PointF(300.5, 100.5));
Pen.Width := 5;
Pen.Color := clBlue;
// Second line
DrawLine(D2D1PointF(100.5, 150.5), D2D1PointF(300.5, 150.5));
Pen.Width := 10;
Pen.Color := clRed;
// Third line
DrawLine(D2D1PointF(400.5, 100.5), D2D1PointF(600.5, 200.5));
RenderTarget.EndDraw;
finally
LD2DCanvas.Free;
end;
end
else
ShowMessage
(‘Direct2D not supported on Windows XP. Please run the example on Windows 7 or Windows 8.’);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
LD2DCanvas: TDirect2DCanvas;
begin
// Turn off mouse drawing if on
CheckBox1.Checked := false;
if TDirect2DCanvas.Supported then
begin
LD2DCanvas := TDirect2DCanvas.Create(Canvas, ClientRect);
with LD2DCanvas do
try
BeginDraw;
RenderTarget.Clear(D2D1ColorF(1.0, 1.0, 1.0, 1.0));
// First Rectangle
DrawRectangle(D2D1RectF(