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

FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes


Ryzen 9 5950x: One Billion Lines Of Delphi Code Compiled In ~5 Minutes On 16 Cores


DelphiCon 2020 FireMonkey Sessions Available Starting November 19


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

Sign up for our Newsletter and
stay informed


Leave a Reply