RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TGraphic.Transparent Property

Indicates whether the image covers its rectangular area.

Pascal
property Transparent: Boolean;
C++
__property Boolean Transparent;

Use Transparent to specify that the graphic be drawn transparently. Some descendants of TGraphic such as TIcon and TMetafile are always transparent, so setting the property for those objects does not change their behavior. However, the TBitmap graphic's drawing is affected by this property. The TImage component sets this property to be the same as its Transparent property to achieve transparent painting. 

When the Transparent property is set to True, you can either specify a color as the transparent color or you can use the default color, which is the pixel in the lower left. The specified color is not displayed in the graphic, which lets the background show through. This can be useful in layering and for non-rectangular graphics.  

C++ Examples: 

 

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  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);
    bitmap->TransparentMode = tmAuto;
    Form1->Canvas->Draw(50, 50, bitmap);
  }
  catch (...)
  {
    ShowMessage("Could not load or display bitmap");
  }
  delete 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) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!