Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: delphi and anti-alias


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 8 - Last Post: Dec 18, 2015 1:15 PM Last Post By: Alex Sv
loki loki

Posts: 787
Registered: 7/1/02
delphi and anti-alias  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 16, 2015 4:33 AM
Hello,

I work on 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 whithout any anti-alias at all ! pixel perfect copy from bitmap to the canvas

thanks by advance for your help !
loki loki

Posts: 787
Registered: 7/1/02
Re: delphi and anti-alias  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 16, 2015 4:42 PM   in response to: loki loki in response to: loki loki
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 urly round without any anti-aliasing :(

what i miss ??

many thanks by advance for any helps !
Alex Sv

Posts: 92
Registered: 1/11/04
Re: delphi and anti-alias  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 17, 2015 7:42 PM   in response to: loki loki in response to: loki loki
Check that Bitmap.Scale property is the same as current screen scale.

loki loki wrote:
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 urly round without any anti-aliasing :(

what i miss ??

many thanks by advance for any helps !
loki loki

Posts: 787
Registered: 7/1/02
Re: delphi and anti-alias  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2015 1:26 AM   in response to: Alex Sv in response to: Alex Sv
Check that Bitmap.Scale property is the same as current screen scale.

yes, screen.scale=1 and bitmapscale=1 :( 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;
Alex Sv

Posts: 92
Registered: 1/11/04
Re: delphi and anti-alias  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2015 4:58 AM   in response to: loki loki in response to: loki loki
Bitmap scale should be compared with

SS:=TPlatformServices.Current.GetPlatformService(IFMXScreenService) as IFMXScreenService;
GlobalScreenScale := SS.GetScreenScale;

Yes, FMX canvas is not thread safe and also is very slow.
On Android there is other issues: no RTL (BiDi) support, no correct text rendering (kerning pairs, baseline adjustment, etc.).
That's why I had to create native Android canvas support for HTML Component Library, it's the only way to get smooth scrolling (same as in native applications) and correct text rendering.

loki loki wrote:
Check that Bitmap.Scale property is the same as current screen scale.

yes, screen.scale=1 and bitmapscale=1 :( 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;
loki loki

Posts: 787
Registered: 7/1/02
Re: delphi and anti-alias  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2015 8:40 AM   in response to: Alex Sv in response to: Alex Sv
Yes, FMX canvas is not thread safe and also is very slow.
On Android there is other issues: no RTL (BiDi) support, no correct text rendering (kerning pairs, baseline adjustment, etc.).
That's why I had to create native Android canvas support for HTML Component Library, it's the only way to get smooth scrolling (same as in native applications) and correct text rendering.

you say "i had" so you already made it? can you share your canvas source with me? i will test it and debug it :) especially the text rendering part ...
Alex Sv

Posts: 92
Registered: 1/11/04
Re: delphi and anti-alias  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2015 8:48 AM   in response to: loki loki in response to: loki loki
Sorry, it is a part of commercial library http://delphihtmlcomponents.com

loki loki wrote:
Yes, FMX canvas is not thread safe and also is very slow.
On Android there is other issues: no RTL (BiDi) support, no correct text rendering (kerning pairs, baseline adjustment, etc.).
That's why I had to create native Android canvas support for HTML Component Library, it's the only way to get smooth scrolling (same as in native applications) and correct text rendering.

you say "i had" so you already made it? can you share your canvas source with me? i will test it and debug it :) especially the text rendering part ...
loki loki

Posts: 787
Registered: 7/1/02
Re: delphi and anti-alias  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2015 1:05 PM   in response to: Alex Sv in response to: Alex Sv
Alex Sv wrote:
Sorry, it is a part of commercial library http://delphihtmlcomponents.com

your library sound very promising !! and the idea is very good ... congratulation !!
i don't really need an html functionality right now, just some example about how to work directly on the canvas
i need to know how to use native canvas on Android

Edited by: loki loki on Dec 18, 2015 1:07 PM
Alex Sv

Posts: 92
Registered: 1/11/04
Re: delphi and anti-alias  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2015 1:15 PM   in response to: loki loki in response to: loki loki
Contact me please via email.

loki loki wrote:
Alex Sv wrote:
Sorry, it is a part of commercial library http://delphihtmlcomponents.com

your library sound very promising !! and the idea is very good ... congratulation !!
i don't really need an html functionality right now, just some example about how to work directly on the canvas
i need to know how to use native canvas on Android

Edited by: loki loki on Dec 18, 2015 1:07 PM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02