delphi Android实例-TRectangle加载图片(XE8+小米2)


本文整理自网络,侵删。

 
结果:

1.加载图片很流畅,可以做背景用。

2.现在是加载了正形与圆形,其他形状能不能加载呢?自己测试哦,要多动手才行。

3.需要把图片打到包里哦(路径为“assets\internal\”)。

 

实例代码:

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects,
  FMX.Controls.Presentation, FMX.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Rectangle1: TRectangle;
    Label1: TLabel;
    Ellipse1: TEllipse;
    Button2: TButton;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses
  system.IOUtils;//需要引入
{$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Rectangle1.Width := 144;
  Rectangle1.Height := 144;
  Rectangle1.Stroke.Kind := TBrushKind.bkNone; //边框类型,无
  Rectangle1.Fill.Kind := TBrushKind.bkBitmap; //填充类型,图片
  Rectangle1.Fill.Bitmap.WrapMode := TWrapMode.wmTileStretch; //拉伸
  Rectangle1.Fill.Bitmap.Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, '144.jpg'));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Ellipse1.Width := 144;
  Ellipse1.Height := 144;
  Ellipse1.Stroke.Kind := TBrushKind.bkNone; //边框类型,无
  Ellipse1.Fill.Kind := TBrushKind.bkBitmap; //填充类型,图片
  Ellipse1.Fill.Bitmap.WrapMode := TWrapMode.wmTileStretch; //拉伸
  Ellipse1.Fill.Bitmap.Bitmap.LoadFromFile(TPath.Combine(TPath.GetDocumentsPath, '144.jpg'));
end;

end.

相关阅读 >>

Delphi iddecodermime 对图像编码base64解码成图像文件

Delphi 根据数据库结构生成treeview

Delphi的tservice 服务路径获取 dll中获取文件路径

Delphi 内存管理[5]

Delphi 解析json生成json

Delphi10.2.3实现http异步下载

Delphi fmx自定义对话框样式,多屏幕布局

Delphi exe图标替换

Delphi tidhttp+tidssliohandlersocket+ssl

Delphi thttprio 控件调用webservice超时问题

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...