RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TBitmap.TransparentColor Property

Determines which color of the bitmap is to be transparent when the bitmap is drawn.

Pascal
property TransparentColor: TColor;
C++
__property TColor TransparentColor;

Use TransparentColor to determine how to draw the bitmap transparently. When the TransparentMode property is set to tmAuto (default), TransparentColor returns the color of the first pixel in the bitmap image data. For "bottom-up" bitmaps, the first pixel is the bottom leftmost pixel shown onscreen. For "top-down" bitmaps (less common), the first pixel is in the top left corner shown onscreen.  

If TransparentColor is assigned, the TransparentMode is automatically set to tmFixed so that the new transparent color can be used later. If you want TransparentColor to disregard any assignments and return the bottom leftmost pixel color again, set TransparentMode to tmAuto.  

C++ Examples: 

 

/*
An examples of TBitmap Color, TGraphic Transparent, TBitmap
TransparentMode, TBitmap TransparentColor and TCanvas Draw.
*/

#include <memory>       //for STL auto_ptr class

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  std::auto_ptr<Graphics::TBitmap> bitmap(new Graphics::TBitmap);
  try
  {
    bitmap->LoadFromFile("..\\FACTORY.BMP ");
    bitmap->Transparent = true;
    bitmap->TransparentColor = bitmap->Canvas->Pixels[50][50];
    Form1->Canvas->Draw( 0, 0, bitmap.get());
    bitmap->TransparentMode = tmAuto;
    Form1->Canvas->Draw(50, 50, bitmap.get());
  }
  catch (...)
  {
    ShowMessage("Could not load or display bitmap");
  }
}

 

Delphi Examples: 

procedure TForm1.Button1Click(Sender: TObject);
var
  Bitmap : TBitMap;
begin
  Bitmap := TBitmap.Create;
  try
    with Bitmap do begin
      LoadFromFile('factory.bmp');
      Transparent := True;
      TransParentColor := BitMap.canvas.pixels[50,50];
      Form1.Canvas.Draw(0,0,BitMap);
      TransparentMode := tmAuto;
      Form1.Canvas.Draw(50,50,BitMap);
    end;
  finally
    Bitmap.Free;
  end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!