Site icon Learn C++

Learn About Bitmap Operations In C++ Builder (FireMonkey)

Bitmap is a standard for reading and writing pixels of images of applications on all platforms (Windows, MacOS, iOS, Android, Linux, …). A Bitmap includes bitmap information and full uncompressed image in pixels. Each pixel of this uncompressed image consists 4 color members called ARGB (Alpha Red Green Blue) and it can be set or shown as 0xAABBCCDD in hexadecimal format.

TBitmap is a powerful graphic object used to create, manipulate and store images in memory and stored as a BMP image file (or in compressed types like JPG, PNG,…) on a disk. At the time of this writing C++Builder does not support Android64 or macOS64. Using Bitmaps and doing drawings, effects and analyzing pixels are easy by using C++ Builder, Delphi programming languages.  TBitmap contains an internal image of the bitmap graphic and automatically manages realization of the palette when drawn. It also has an internal Canvas, that allows you to draw pixels, lines, etc. Manipulating and copying image is very easy by using TBitmap Classes. All methods, properties and events of TBitmap can be found on this TBitmap wiki and It is possible to use multi-resolution bitmaps

Bitmaps can be easily used by TImage component in C++ Builder which has Bitmap property and it is easy to display a graphical image or graphical image files (BMP, PNG, JPG,… ) on a control. On C++Forms, Just drag Image component from the Palette (right side ) and double clikc MultiRessBitmap property from the Object Inspector (left side). Click this icon to import an image.

Moreover, you can do a lot of operations easily and faster on these images in your C++ codes. Loading, saving, drawing, copying, reading pixels etc.
Now lets see some of bitmap operation examples in C++ as listed below;

Creating a New Bitmap and Deleting Bitmap from Memory

[crayon-660676e97f98f715838990/]

Setting Size of Bitmap, Resizing Bitmaps

[crayon-660676e97f996815634876/]
[crayon-660676e97f998743437831/]

In these examples you cant see these bitmaps, because it is totaly in 0x00000000 form, which means it is fully transparent. You need to clear this blank bitmap in color if you want to see.

Clearing Bitmap in Colors

[crayon-660676e97f99a612771057/]

Copying a Bitmap to Another Bitmap

[crayon-660676e97f99b169810364/]

Loading Bitmap from a File and Saving Bitmap to a File

[crayon-660676e97f99d908937115/]

Drawing A Bitmap on to Another Bitmap (Including Transparency and Resizing Features)
In C++ Builder with FireMonkey C++ projects (Windows, Mac-OS, iOS, Android) , you can draw a bitmap on to another bitmap easily and faster by using DrawBitmap command. This works really fast because of locking bitmap data area by BeginScene() and EndScene() commands and you directly manuplate over the memory.

[crayon-660676e97f9b2060065383/]

This example shows how to draw a bitmap on to another canvas of a bitmap with explanations of parameters.

[crayon-660676e97f9b6197678034/]

To do drawings on the Canvas of Bitmaps, please see details about How to Draw on Canvas in C++.

Mapping Bitmap to Analyze Pixels or Edit
We use Map to read or write pixels of bitmaps as below. In this example you need a Image component and a bitmap loaded in it.

[crayon-660676e97f9b8877141443/]

This example gets each pixels, adds Red, Green, Blue colors, and sets mean ARGB color to acr;

[crayon-660676e97f9b9479173549/]

Exit mobile version