C++C++11C++14C++17Language FeatureLearn C++

Learn To Create Alpha Color Bitmap From A Bitmap By A Given Color In Modern C++

Photoshop, GIMP and other professional Photo Editors are capable to convert one color to a alpha color. You choose a color and all same colors of pixels are goes to alpha color which is transparent. These kind of images are good to blend in front o another background of images. You can also add glamorous effects, like gloom, shadows etc. on those images.

In this post we will present to how to modify bitmap color to alpha colors. Before this we highly recommend you to read Colors In Modern C++ For Windows Development and Learn About Bitmap Operations In C++ Builder (FireMonkey) posts. These will help you get more information about ARGB color format and Bitmap Operations.

In C++ Builder, FireMonkey (FMX) framework offers great and faster operations on bitmaps. To read or write pixels of a bitmap first you must obtain its Bitmap Data (TBitmapData). Then you can get color of a pixel at a x,y coordinates as below;

You can also set color of a pixel at that x,y coordinate as below;

If you want to set to full transparent color (alpha background) , you must set color to 0x0 (actually it is 0x00000000 in ARGB format) as below

Now let’s see full function that converts a color in bitmap to bitmap with alpha color.

This C++ Builder Firemonkey Console Application below reads a bitmap and converts white color pixels to alpha color pixels and saves bitmap to another file.

Find out more about developing Windows apps with C++Builder on Embarcadero’s website!


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

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++C++11C++14C++17Generic ProgrammingLearn C++Templates

What Is A Template In C++?

C++C++17Code SnippetComponentsIteratorsLearn C++

What Are The Boost C++ Libraries?

C++C++17Introduction to C++Learn C++Syntax

Learn Bits and How To Use std::bitset In C++

C++C++17IteratorsLearn C++

How To Use Insert In std::map In Modern C++

Worth reading...
Learn About Bitmap Operations In C++ Builder (FireMonkey)