TBitmap.Canvas Property
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: 

 

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!