Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetDelphiFiremonkeyIOSOSXWindows

Get Direct Pixel Access To Bitmaps In Delphi XE5 Firemonkey On Android And IOS

Delphi XE5 Firemonkey Pixel ScanlineI’m working with a developer to build a component and one of the issues we ran into is that when you take a screenshot of a set of controls with Delphi XE5 Firemonkey and then put it into a TImage control Firemonkey applies an antialias to the image. This is mainly an issue around text. Since we were looking for a pixel perfect representation of the controls as a bitmap I looked for some way to help remove the antialias effect from the bitmap. The background of the controls is transparent so one idea I came up with was to change all of the partially transparent pixels below a certain threshold to fully transparent. On the Embarcadero site I found this TestAlphaColorToPixel() function which shows changing every third line to solid red. I modified this function to read each pixel, check it’s opacity, and if it is below the opacity threshold change it to completely transparent. It does not completely solve the antialiasing problem but it helps slightly. You can take this function and modify it to suit your own needs for modifying all of the pixels in a bitmap. TAlphaColorRec has four properties you can use for this which are A for alpha, R for red, B for blue, and G for green. This function should work on Android, IOS, Windows, and OSX. You can take a look at the other PixelFormat functions including scanline access using ScanLineToAlphaColor.

If you know of a way to have Firemonkey not automatically antialias bitmaps or a better way to deantialias a bitmap let me know. I’ve also tried a Sharpen effect but that causes artifacts on edges of controls like TPanel. There are two StackOverflow answers which explain the issue here and here.

Check out the TBitmap.Map method over at Embarcadero which is the key to unlock direct access to the bitmap which making this function work.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts
DelphiFiremonkeyIDEIOSOSXWindows

DelphiCon 2020 FireMonkey Sessions Available Starting November 19

AndroidC++BuilderDelphiDemoFiremonkeyWindows

Powerful Commercial Gorilla3D Framework Upgraded For Delphi FireMonkey On Windows And Android

AndroidC++BuilderCode SnippetDelphiDemoFiremonkeyIOSOSXShowcaseWindows

Powerful Cross Platform Email App Sample In Delphi 10.4.1 FireMonkey For Android And IOS

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

Significant Update Available For Delphi FireMonkey 10.4.1 On Android, IOS, OSX, Windows, And Linux

Sign up for our Newsletter and
stay informed

3 Comments

Leave a Reply