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!

Related posts
C++Learn C++Videos

Learn C++ with Heterogeneous Programming in C++ with SYCL 2020 by Michael Wong and Gordon Brown (CPPCon 2020) Video

C++Language FeatureLearn C++

Learn To Modernize Appearance Of Multi-Platform C++ Builder FMX Applications By Using Styles

C++Learn C++Videos

Learn C++ With Back to Basics: Unit Tests by Ben Saks (CPPCon 2020) Video

C++Language FeatureLearn C++

Learn To Modernize Appearance Of Windows VCL Applications By Using Powerful Styles

Worth reading...
Quickly Learn How To Use Canvas Drawing In C++ On Windows