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;

close

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.

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++Introduction to C++Language FeatureLearn C++

How To Use The Comprehensive Form Properties In C++ VCL Apps

C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Add Characters to Wide Strings in Modern C++

C++ComponentsLanguage FeatureLearn C++

How To Create Gorgeous Transparent App Windows With C++

C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Get A Substring of a Wide String in C++

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