2

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...

Jim
  • 45
  • 7
  • If the compiler doesn't even recognize the function, using it is likely to be seriously problematic. My immediate advice would be to consider using [`AlphaBlend`](https://learn.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-alphablend) instead. – Jerry Coffin Dec 16 '18 at 06:33
  • `DrawTransparent` is a protected method so you can't call it directly, but perhaps this works `destination_bitmap->Canvas->Draw(0, 0, source_bitmap->Picture->Graphic, 50);` You may need to do `source_bitmap->Transparent = true;` too. Haven't tested it myself. – Ted Lyngmo Dec 16 '18 at 06:46
  • I'm sure I am doing something wrong.. There are nuances to C++ that I still don't get.. There is probably some way to declare it or something... It is supposed to be a part of the existing graphics system, or it appears so - like StretchDraw() so I figured it would be easier to integrate... But I will look into the AlphaBlend, thanks. – Jim Dec 16 '18 at 06:49
  • What is a protected method? Thanks all info helps... – Jim Dec 16 '18 at 06:51
  • There's a good description of what a protected member (method or variable) is here: [access specifiers @ cppreference](https://en.cppreference.com/w/cpp/language/access). – Ted Lyngmo Dec 16 '18 at 06:58
  • @Ted Lyngmo: That seems to work! You ROCK.... Post it as an answer if you like so I can give you the credit... – Jim Dec 16 '18 at 07:54
  • @Jim great, answer added :-) – Ted Lyngmo Dec 16 '18 at 08:00

1 Answers1

0

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.

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • This does draw a blend....:) Just need to get the new bitmap to work with transparent color, so far doesn't want to...even using Transparent = True and specifying a color... – Jim Dec 16 '18 at 08:16