zeus
zeus

Reputation: 13367

How to retrieve the dpi of the current device?

Is there any functions to retrieve the DPI (or the screen density) of the mobile device (android/ios)? I m under Delphi Sydney.

Upvotes: 1

Views: 772

Answers (1)

Dalija Prasnikar
Dalija Prasnikar

Reputation: 28516

In FireMonkey various platform information is accessible through platform services. For retrieving PPI (DPI) and device display scale you can use IFMXDeviceMetricsService or IFMXScreenService

var
  MetricsService: IFMXDeviceMetricsService;
  Metrics: TDeviceDisplayMetrics;
  PPI: Integer;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXDeviceMetricsService, MetricsService) then
  begin
    Metrics := MetricsService.GetDisplayMetrics;
    PPI := Metrics.PixelsPerInch;
  end;
end;


var
  ScrService: IFMXScreenService;
  ScrScale: Single;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, ScrService) then
  begin
    ScrScale := ScrService.GetScreenScale;
  end;
end;

List of all FMX Platform services and information you can find at FireMonkey Platform Services

Note: Some services, like IFMXDeviceMetricsService, are not listed in documentation.

Upvotes: 5

Related Questions