bLight
bLight

Reputation: 865

On Android FMX Canvas's DrawBitmap uses screen scale instead of pixels

I want to draw multiple sprites on a TBitmap using the Canvas's DrawBitmap function.

I am setting the TBitmap size taking the screen scale into account:

if TPlatformServices.Current.SupportsPlatformService(
  IFMXScreenService, IInterface(clientScreenService)) then
    clientScreenScale := clientScreenService.GetScreenScale else
    clientScreenScale := 1;

MyImage.Bitmap.SetSize(
  MainForm.ClientWidth*clientScreenScale,
  MainForm.ClientHeight*clientScreenScale);

I am trying to draw my sprite centered within my bitmap:

PosX := Trunc((MyImage.Bitmap.Width-spriteSize)/2);
PosY := Trunc((MyImage.Bitmap.Height-spriteSize)/2);
MyImage.Bitmap.Canvas.DrawBitmap(
  SpriteBitmap,
  RectF(0,0,spriteSize,spriteSize),
  RectF(PosX,PosY,PosX+spriteSize,PosY+spriteSize),
  1,True);

On windows everything works as expected, but under Android (ScreenScale=4) the sprite is drawn at x4 the size (compared to windows) and at x4 the X/Y position offset specified by the target RectF.

This seems to imply that under Android the canvas's DrawBitmap function works at ScreenScale rather than Pixel scale, something that isn't documented anywhere.

Is this a Delphi bug? Missing documentation? something I did wrong in the code?

Upvotes: 2

Views: 756

Answers (1)

zeus
zeus

Reputation: 12955

Drawbitmap (and all canvas operation) work always at the virtual pixel level not at the physical pixel level. you also need to take in account that when working at virtual pixel level you may see anti aliasing artifact because virtual pixel and physical pixel are not necessarily aligned

Normally working only on Tbitmap don't care of the screenscale, maybe the property image.bitmap.screenscale or scale or something like this i don't remember the name is set to 4 in your sample ?

Upvotes: 2

Related Questions