3

I am using the canvas draw functions drawrect and filltext to draw onto a Tbitmap but I don't want the results antialiased. Anyone know how to do that ?

Working with OSX and Delphi XE3 (but have XE4 and XE5 if needed)

David Peters
  • 220
  • 1
  • 10
  • Maybe the last answer at http://stackoverflow.com/questions/10592874/firemonkey-fmx-bitmap-and-colours is of help? – Gerard Jan 02 '14 at 23:30
  • Thanks for the link. Aligning drawing co-ordinates with pixels will only avoid anti-aliasing for vertical and horizontal lines. Its not going to be of help with text or rounded corners - at least thats what I assume, there is no help in the documentation as usual. What I need to do is turn it off. – David Peters Jan 03 '14 at 12:10
  • Please provide simple code example that demonstrates the problem. – Marcus Adams Jan 06 '14 at 19:25

2 Answers2

1

Is the problem:

  1. the bitmap you create seems to have anti-aliasing present in the data?
  2. or have you got a good bitmap and want to disable anti-aliasing in the viewer/display?

If it is the former, have you checked that the anti-aliasing is actually present in the bitmap, and not introduced by your viewer?

In the past I've found it useful to draw a black-on-white test pattern, and display the image at 1:1 scale. Irfanview is a nice tool for viewing at 'true' scale. Then use a loupe/peak/lens to get a close-up of the actual pixels.

Black-on-white test patterns are particularly good since you should be able to see (hopefully) that the R,G and B sub-pixels are all equally illuminated when there is no anti-aliassing present. If you draw a black-on white pattern and you get solitary bright sub-pixels then you've definitely got anti-aliassing (or some other form of corruption!).

My experience has been that image viewers often do interpolation for you, and it can be tricky to see what is going on unless you look at the actual bitmap data or have a close-up look at the unscaled image...

GnomeDePlume
  • 1,642
  • 2
  • 15
  • 31
  • Antialiasing is added by all canvas drawing functions in Firemonkey by default - so yes its in the bitmap. I am reading the bitmap pixel by pixel which is how the problem showed itself. In VCL with Delphi 6 there is no problem. Start off with a blank white bitmap and draw on it and you will see the effect. Only straight lines aligned to the pixels will not show antialiasing. – David Peters Jan 08 '14 at 11:57
  • @David Drat. Okay, it [sounds as though](http://stackoverflow.com/questions/641401/disable-antialiasing-for-a-specific-gdi-device-context) rendering is done by the GDI+ canvas on a per-font basis. Changing back to a GDI canvas would remove anti-aliasing support, but is horribly regressive. You could try to set the global-level settings to prevent AA being allowed when the font is drawn: do have you tried playing with the following parameters: `GlobalUseHWEffects`, `EGlobalUseDirect2D`, `GlobalUseGDIPlusClearType`, `GlobalDisableFocusEffect`? – GnomeDePlume Jan 08 '14 at 14:11
  • @David Alternatively, The embarcadero website [lets slip](http://docwiki.embarcadero.com/RADStudio/XE4/en/What's_New_in_Delphi_and_C%2B%2BBuilder_XE4) that AA can be enabled (disabled?) using the FMX.Form.Quality property. I don't have an install, or I'd go and prod this a little further... – GnomeDePlume Jan 08 '14 at 14:19
  • form.quality not available in XE3. I had trouble getting XE5 to run but now I have, form.quality is read only. Maybe it can be overridden with a helper function or something. – David Peters Jan 09 '14 at 14:26
  • @ David That's a pain. Any luck with the Global parameters? If I find anything else, I'll let you know... – GnomeDePlume Jan 09 '14 at 17:47
  • Thanks for your help. No success with param, helper no use as canvas not created in my unit but deep in Firemonkey source. Wrote my own line/shape routines working on the bitmap pixels. For text, I output anti-aliased and then modify pixels using threshold to choose black or white. Works well enough for my use but being able to select the canvas quality would be much better. I tried modifying the Firemonkey source but couldn't find instructions to build it - adding the graphics unit to the project uses statement didn't work due to other units being dependant on the same types. – David Peters Jan 15 '14 at 12:19
0

Hi in the drawBitmap method you need to set HighSpeed parameter to "True", in the sample below:

NewBitmap.Canvas.DrawBitmap(SmallBmp, RectF(0, 0, SmallBmp.Width, SmallBmp.Height), RectF(0, 0, NewBitmap.Width, NewBitmap.Height), 1,**True**);

rgds Ivan

Ivan Revelli
  • 363
  • 4
  • 8