RAD Studio VCL Reference
|
Indicates whether the image covers its rectangular area.
property Transparent: Boolean;
__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:
/* 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!
|