标签:
结果:
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 type 11 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 private 21 { Private declarations } 22 public 23 { Public declarations } 24 end; 25 26 var 27 Form1: TForm1; 28 29 implementation 30 uses 31 system.IOUtils;//需要引入 32 {$R *.fmx} 33 {$R *.NmXhdpiPh.fmx ANDROID} 34 35 procedure TForm1.Button1Click(Sender: TObject); 36 begin 37 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 begin 47 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)
标签:
原文地址:http://www.cnblogs.com/FKdelphi/p/4784503.html