c++tbitmap

How to use DrawTransparentBitmap() in C++ Builder


Just trying to figure out how to use DrawTransparent in C++ Builder to draw a bitmap or tbitmap with an alpha channel so that the drawn image is semi-transparent with the background image.

I looked all over the place and on this site but can't find anything other than a note that this as well as DrawTransparentBitmap exists..

In the help it is listed as follows:

virtual void __fastcall DrawTransparent(TCanvas* ACanvas, const 
System::Types::TRect &Rect, System::Byte Opacity);

However there are no code examples. The compiler doesn't recognize the procedure name and it does not appear as a method of tbitmap...

I am still new to C++ and I could really use some help with this...


Solution

  • DrawTransparent is a protected method so you can't call it directly, but this should work:

    // opacity 50 
    destination_bitmap->Canvas->Draw(0, 0, source_bitmap->Picture->Graphic, 50);
    

    You may need to do source_bitmap->Transparent = true; too.