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.

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...
Quickly Learn How To Use Canvas Drawing In C++ On Windows