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.
作者:疯狂Delphi
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
欢迎关注我,一起进步!扫描下方二维码即可加我