標籤:
結果:
1.載入圖片很流暢,可以做背景用。
2.現在是載入了正形與圓形,其他形狀能不能載入呢?自己測試哦,要多動手才行。
3.需要把圖片打到包裡哦(路徑為“assets\internal\”)。
執行個體代碼:
1 unit Unit1; 2 3 interface 4 5 uses 6 System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects, 8 FMX.Controls.Presentation, FMX.StdCtrls; 9 10 type11 TForm1 = class(TForm)12 Button1: TButton;13 Rectangle1: TRectangle;14 Label1: TLabel;15 Ellipse1: TEllipse;16 Button2: TButton;17 Label2: TLabel;18 procedure Button1Click(Sender: TObject);19 procedure Button2Click(Sender: TObject);20 private21 { Private declarations }22 public23 { Public declarations }24 end;25 26 var27 Form1: TForm1;28 29 implementation30 uses31 system.IOUtils;//需要引入32 {$R *.fmx}33 {$R *.NmXhdpiPh.fmx ANDROID}34 35 procedure TForm1.Button1Click(Sender: TObject);36 begin37 Rectangle1.Width := 144;38 Rectangle1.Height := 144;39 Rectangle1.Stroke.Kind := TBrushKind.bkNone; //邊框類型,無40 Rectangle1.Fill.Kind := TBrushKind.bkBitmap; //填滿類型,圖片41 Rectangle1.Fill.Bitmap.WrapMode := TWrapMode.wmTileStretch; //展開42 Rectangle1.Fill.Bitmap.Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, ‘144.jpg‘));43 end;44 45 procedure TForm1.Button2Click(Sender: TObject);46 begin47 Ellipse1.Width := 144;48 Ellipse1.Height := 144;49 Ellipse1.Stroke.Kind := TBrushKind.bkNone; //邊框類型,無50 Ellipse1.Fill.Kind := TBrushKind.bkBitmap; //填滿類型,圖片51 Ellipse1.Fill.Bitmap.WrapMode := TWrapMode.wmTileStretch; //展開52 Ellipse1.Fill.Bitmap.Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, ‘144.jpg‘));53 end;54 55 end.
Android執行個體-TRectangle載入圖片(XE8+小米2)