程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Direct2D (3) : 使用浮點參數繪制基本圖形

Direct2D (3) : 使用浮點參數繪制基本圖形

編輯:Delphi

{相關方法} 
TDirect2DCanvas.DrawEllipse(); 
TDirect2DCanvas.DrawLine(); 
TDirect2DCanvas.DrawRectangle(); 
TDirect2DCanvas.DrawRoundedRectangle(); 
TDirect2DCanvas.FillEllipse(); 
TDirect2DCanvas.FillRectangle(); 
TDirect2DCanvas.FillRoundedRectangle(); 
 
{相關結構} 
TD2DPoint2f      (或 D2D_POINT_2F) //浮點點結構; 構建函數 D2D1PointF(); 可從 TPoint 隱式轉換到 TD2DPoint2f 
TD2D1Ellipse    (或 D2D1_ELLIPSE) //浮點橢圓結構; 構建函數 D2D1Ellipse(); 
TD2D1RectF      (或 D2D1_RECT_F) //浮點矩形結構; 構建函數 D2D1RectF(); 
TD2D1RoundedRect (或 D2D1_ROUNDED_RECT) //浮點圓角矩形結構; 構建函數 D2D1RoundedRect(); 

  測試代碼:

uses Direct2D, D2D1; 
 
procedure TForm1.FormPaint(Sender: TObject); 
var 
  cvs: TDirect2DCanvas; 
  fPt: TD2DPoint2f; 
  fLeft,fTop: Single; 
begin 
  fPt := D2D1PointF(ClientWidth / 2, ClIEntHeight / 2); 
  fLeft := ClIEntWidth / 4; 
  fTop := ClIEntHeight / 4; 
 
  cvs := TDirect2DCanvas.Create(Canvas, ClIEntRect); 
  cvs.BeginDraw; 
  cvs.Pen.Color := clRed; 
  cvs.Pen.Width := 2; 
 
  cvs.Brush.Color := clBlack; 
  cvs.FillRectangle(D2D1RectF(fLeft, fTop, fLeft*3, fTop*3)); 
  cvs.Brush.Color := clGreen; 
  cvs.FillRoundedRectangle(D2D1RoundedRect(D2D1RectF(fLeft, fTop, fLeft*3, fTop*3), 32, 32)); 
  cvs.Brush.Color := clBlue; 
  cvs.FillEllipse(D2D1Ellipse(fPt, fLeft, fTop)); 
 
  cvs.DrawRectangle(D2D1RectF(fLeft, fTop, fLeft*3, fTop*3)); 
  cvs.DrawRoundedRectangle(D2D1RoundedRect(D2D1RectF(fLeft, fTop, fLeft*3, fTop*3), 32, 32)); 
  cvs.DrawEllipse(D2D1Ellipse(fPt, fLeft, fTop)); 
  cvs.DrawLine(D2D1PointF(fLeft, fTop), D2D1PointF(fLeft*3, fTop*3)); 
 
  cvs.EndDraw; 
  cvs.Free; 
end; 
 
procedure TForm1.FormResize(Sender: TObject); 
begin 
  Repaint; 
end; 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved