RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TBitmap.Canvas Property

Provides access to a drawing surface that represents the bitmap.

Pascal
property Canvas: TCanvas;
C++
__property TCanvas Canvas;

Canvas allows drawing on the bitmap by providing a T Canvas object for this purpose. Drawing on the canvas effectively modifies the underlying bitmap image pixels. Any canvas operation is valid on a bitmap (not just Draw and StretchDraw) including line drawing, rectangles, and circles. The bitmap object is passed as a parameter to these methods. 

A canvas object is created automatically for the bitmap and the property is read-only.  

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!