Search code examples
delphibitmapscalefiremonkeydelphi-xe8

How to know the scale for a bitmap in Delphi XE8?


I have an image component for drawing an autograph. At the moment you have to set a scale property mannually in order to let it draw correctly, because each device has an other screen density.

Is there a way to calculate the scale or not to have to use the scale for both Android and iOS?

As you can read in the following link every android and iOS device have a different screen density: http://docwiki.embarcadero.com/RADStudio/XE8/en/Using_Multi-Resolution_Bitmaps

Also tried this method but it does not give the correct scale:

function GetScreenScale: Single;
var
   ScreenService: IFMXScreenService;
begin
   Result := 1;
   if TPlatformServices.Current.SupportsPlatformService (IFMXScreenService, IInterface(ScreenService)) then
   begin
      Result := ScreenService.GetScreenScale;
   end;
end;

Solution

  • Solution:

    function GetScreenScale: Single;
    var
       Service : IFMXScreenService;
    begin
       Service := IFMXScreenService(
          TPlatformServices.Current.GetPlatformService(IFMXScreenService));
       Result := Service .GetScreenScale;
    end;