C++C++11C++14C++17Learn 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

Setting Size of Bitmap, Resizing Bitmaps

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

Copying a Bitmap to Another Bitmap

Loading Bitmap from a File and Saving Bitmap to a File

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.

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

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.

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

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20

What Is The Stack (std::stack) In Modern C++?

C++C++11C++14C++17C++20Learn C++

What Is The Queue (std::queue) In Modern C++?

C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?

C++C++14C++17C++20Learn C++

What Are The Deprecated C++14 Features In C++17?

Worth reading...
Introduction To C++ Windows Development With C++Builder