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.

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

Learn about C++ Encapsulation

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

Discover Class Methods in C++

C++Learn C++Videos

Learn C++ With Monoids, Monads, and Applicative Functors: Repeated Software Patterns (CPPCon 2020) Video

C++Learn C++Videos

Learn C++ With Pipes: How Plumbing Can Make Your C++ More Expressive by Jonathan Boccara (CPPCon 2020) Video

Worth reading...
Top C++ Compilers for Windows in 2020
en_USEnglish