Site icon Learn 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;

[crayon-660694b6c2756433720401/]

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

[crayon-660694b6c275f938341746/]

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

[crayon-660694b6c2761698318724/]

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

[crayon-660694b6c2763642693519/]

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.

[crayon-660694b6c2768410662278/]

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

Exit mobile version