Skip to content Skip to sidebar Skip to footer

How To Work With Anti-alias On Delphi Firemonkey And Android

I work on delphi xe7 with firemonkey and testing on android. When i work on a device that have a normal resolution of 1 (scene.scale=1) then component like TRoundRect, TPie, etc pr

Solution 1:

If we talk about Firemonkey:

  1. TImage has the property "DisableInterpolation: boolean"
  2. TForm has the property "Quality: TCanvasQuality = (SystemDefault, HighPerformance, HighQuality)" — it is works in design-time

Important to know:

  1. Anti-aliasing is very expensive operation, this is disabled by default on mobile platforms.
  2. The same anti-aliasing should be supported by the device. To Support multisampling the OpenGL must have GL_EXT_multisampled_render_to_texture property. If the device hardware does not support multisampling, the AA will not be.

Solution 2:

If you are seeing weird anti-aliasing on some controls, I would recommend that you check that the controls do not have fractional position and size values, make sure to use trunc/round on the position or the GPU canvas uses some low-quality interpolation effect on top of any anti-aliasing.

If you plan to do per-pixel manual adjustments, I recommend that you use optimized color-conversion code (scanline <> TAlphaColor) as the built-in code is designed for clear code and not performance: https://github.com/bLightZP/OptimizedDelphiFMXScanline

As for drawing anti-aliased circles with pictures in them, I found the easiest way is to generate an anti-aliased opacity map and apply it to a TImage's TBitmap. You can find code for generating an anti-aliased opacity map here: https://github.com/bLightZP/AntiAliasedCircle


Solution 3:

1. Use FMXNativeDraw by OneChen (Aone), - it's very simple, you even do not need to change your standard code for Canvas - need to add only 2 lines (IFDEF). It also supports TPath. It works on 4 platoforms - Win, Mac, Android, iOS. But you need it only on mobile platforms, because antialiasing works on Win and Mac. I use FMXNativeDraw in my mobile projects and it works very well!

Read this article first with google translate about FMXNativeDraw: http://www.cnblogs.com/onechen/p/6350096.html

Download: https://github.com/OneChen/FMXNativeDraw

Btw if you're using PaintBox Canvas - work as usual. If you need to draw on TBitmap Canvas - prepare Bitmap first:

if Scene <> nil then
  lScale := Scene.GetSceneScale
else
  lScale := 1;

fBitmap.BitmapScale := lScale; 
fBitmap.SetSize(Ceil(Width * lScale), Ceil(Height * lScale) );

2. (optional) Also use ZMaterialComponents, that is a wrapper for FMXNativeDraw (circle, rectangle, line etc). You can place these components on a FMX Form as standard TCircle and others. https://github.com/rzaripov1990/ZMaterialComponents


Post a Comment for "How To Work With Anti-alias On Delphi Firemonkey And Android"