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 produce ugly result because they are not anti-aliased (or the anti-alias is not visible by humain eyes). if i work on high definition device (scene.scale=2 for exemple), then it’s not really a big problem because high definition compensate the problem.

So first question, is their any way to make theses component produce anti-alias graphic ?
also how to draw directly on the canvas an anti-aliased disque (with an image in it) ?

Now when i work on bitmap and on canvas, i notice that the FillText produce anti-aliasing result. this is in someway good for what i want previously (for disque) but a little disaster for text because it’s make them “blur”.
it’s even worse when i do first Mybitmap.canvas.FillText => produce a little of antialias and then later i do MyPaintBox.canvas.DrawBitmap(MyBitmap) it’s will add AGAIN more anti-alias ! the text will be very blur at the end 🙁 it’s sound crazy for me that
doing canvas.drawBitmap without any distorsion in the srcRec and destRect not copy the exact pixel from bitmap to the canvas 🙁

so it’s their a way to :

Call canvas.FillText without any anti-alias or to configure the level of anti-alias.
Call canvas.DrawBitmap without any anti-alias at all ! pixel perfect copy from bitmap to the canvas

thanks by advance for your help !

some solutions i found todays (and theirs problems) :

I found a way how to make all the visual controls (troundrect, etc) with anti-aliasing : set Tform.quality to highQuality !

But now i m facing another very strong problem that i can not understand 🙁
maybe a bug in delphi so if someone can look at it i will be very thanks to him …

when you need a canvas for the form it’s created via

constructor TCanvasGpu.CreateFromWindow(…AQuality: TCanvasQuality)

and here the quality is taken from the MyForm.quality

now the problem is with TBITMAP 🙁 same as previous when we need the canvas for the bitmap it’s created via

constructor TCanvasGpu.CreateFromBitmap(….AQuality: TCanvasQuality=TCanvasQuality.SystemDefault)

but here the problem their is NO PROPERTY at all in the bitmap to setup the quality of the canvas 🙁

so i try this solution :

aBitmap := Tbitmap.Create(w,h);
try

aCanvas := TCanvasManager.CreateFromBitmap(ABitmap, TCanvasQuality.HighQuality);
Try

aCanvas.BeginScene;
try
aCanvas.Fill.Kind := TbrushKind.solid;
acanvas.Fill.Color := $ff000000;
aCanvas.FillRect(TRectF.Create(0, 0, w, h), w / 2, h / 2, ALLcorners, 1);

finally
aCanvas.EndScene;
end;

Finally
aCanvas.Free;
End;
….

and i was thinking i will have now on my bitmap the same antialiasing effect of what i have when i draw directly on the canvas of the form ? absolutely not, nothing change and i still have ugly round without any anti-aliasing 🙁

what i miss ??

EDIT:

The only option i found for now to remove the antialias is to make the bitmap 2x more bigger and reduce it after by 2x! crazy 🙁 but the algorithme of reduction remove the aliased … but the cost of all of this is that the speed become slow, especially when we know that all the graphic function must be done in the main thread 🙁

Now more i think more i say to myself that it’s crazy to have a graphic library that not support multi-thread ! i can not believe that it’s a requirement of openGL and i think now more and more that it’s a bug or bad conception in delphi 🙁
Speaking about the previous point, even if openGL really required that all graphic routines must be done in the main thread (but really i doubt), i don’t understand why delphi not offer on android another TcanvasClass (other than TcanvasGPU) that support multithread ! more crazy is that when you work with TCanvasGPU on Tbitmap, the result will be in any case (as you can see in my previous post) different from what you will have working with TCanvasGPU on the visual component !
now i m looking for function to work directly on pixels grids (old school), that will make me possible to work in multi-thread. but unfortunately their is not to much compatible with firemonley/android 🙁
to finish this is the function i use to draw my bitmap. but as this function must be call in the main thread, it’s slow down my application (especially the scroll) … so if you have any idea to make this more fast or multithread i take 🙂

function DrawAdvertBitmap: Tbitmap;
var aBitmapAliased: Tbitmap;
begin

aBitmapAliased := Tbitmap.Create(trunc(FWidth * fScreenScale) * 2, trunc(FHeight * fScreenScale) * 2);

try

aBitmapAliased.Canvas.BeginScene;
try

aBitmapAliased.canvas.Clear(0);
aBitmapAliased.canvas.Fill.Color := $ff000000;
aBitmapAliased.Canvas.Fill.Kind := TbrushKind.Solid;
aBitmapAliased.Canvas.FillRect(…);

aBitmapAliased.Canvas.Fill.Color := $ff333844;
aBitmapAliased.Canvas.Font.Family := ‘Roboto-Bold’;
aBitmapAliased.Canvas.Font.Size := 12 * fScreenScale * 2;
aBitmapAliased.Canvas.Font.Style := [TFontStyle.fsBold];
aBitmapAliased.Canvas.FillText(…);

finally
aBitmapAliased.Canvas.EndScene;
end;

//reduce by 2 to make antialiased
result := Tbitmap.Create(trunc(FWidth * fScreenScale), trunc(FHeight * fScreenScale));

try

result.Canvas.BeginScene;
try

result.Canvas.Clear(0);
result.Canvas.DrawBitmap(aBitmapAliased,…);

finally
result.Canvas.EndScene;
end;

except
result.Free;
raise;
end;

result.BitmapScale := fScreenScale;

finally
aBitmapAliased.free;
end;

end;

Comments are closed.