Android实例-获取屏幕的物理分辨率

 

相关资料:

http://blog.qdac.cc/?p=1161

 

实例代码:

 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,
 8   FMX.Controls.Presentation, FMX.StdCtrls, FMX.ScrollBox, FMX.Memo;
 9 
10 type
11   TForm1 = class(TForm)
12     Button1: TButton;
13     Label2: TLabel;
14     Memo1: TMemo;
15     procedure Button1Click(Sender: TObject);
16   private
17     { Private declarations }
18   public
19     { Public declarations }
20   end;
21 
22 var
23   Form1: TForm1;
24 
25 implementation
26 uses
27   FMX.BehaviorManager;//需要引入
28 {$R *.fmx}
29 {$R *.LgXhdpiPh.fmx ANDROID}
30 {$R *.Surface.fmx MSWINDOWS}
31 
32 procedure TForm1.Button1Click(Sender: TObject);
33 var
34   DeviceBehavior: IDeviceBehavior;
35   DisplayMetrics: TDeviceDisplayMetrics;
36 begin
37   if TBehaviorServices.Current.SupportsBehaviorService(IDeviceBehavior, DeviceBehavior, Self) then
38   begin
39     DisplayMetrics := DeviceBehavior.GetDisplayMetrics(Self);
40     Memo1.Lines.Add('物理分辨率:');
41     Memo1.Lines.Add(IntToStr(DisplayMetrics.PhysicalScreenSize.cx) + 'x' + IntToStr(DisplayMetrics.PhysicalScreenSize.cy));
42     Memo1.Lines.Add('屏幕尺寸:');
43     Memo1.Lines.Add(
44       FloatToStr(sqrt(
45       DisplayMetrics.PhysicalScreenSize.cx * DisplayMetrics.PhysicalScreenSize.cx / DisplayMetrics.PixelsPerInch / DisplayMetrics.PixelsPerInch +
46       DisplayMetrics.PhysicalScreenSize.cy * DisplayMetrics.PhysicalScreenSize.cy / DisplayMetrics.PixelsPerInch / DisplayMetrics.PixelsPerInch)));
47     Memo1.Lines.Add('PPI:');
48     Memo1.Lines.Add(FloatToStr(DisplayMetrics.PixelsPerInch));
49   end;
50 end;
51 
52 end.
View Code

 

posted on 2017-11-28 21:54  疯狂delphi  阅读(1872)  评论(0编辑  收藏  举报

导航