RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCanvas.Draw Method

Renders the graphic specified by the Graphic parameter on the canvas at the location given by the coordinates (X, Y).

Pascal
procedure Draw(X: Integer; Y: Integer; Graphic: TGraphic);
C++
__fastcall Draw(int X, int Y, TGraphic Graphic);

Call Draw to draw a graphic on the canvas. Draw calls the Draw method of the graphic. The image is rendered into a rectangle determined by the size of the graphic, with the upper left corner at the point (X, Y).  

Graphics can be bitmaps, icons, or metafiles. If the graphic is a TBitmap object, the bitmap is rendered using the value of CopyMode.  

C++ Examples: 

 

/*
The following code draws the graphic in Picture1 in the
top-left corner PaintBox1.  Place a TPaintBox in the form 
and a TImage in the form that contains a picture.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  PaintBox1->Canvas->Draw(0,0, Image1->Picture->Graphic);
}
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: 

{
The following code draws the graphic in Picture1 in the
top-left corner PaintBox1.  Place a TPaintBox in the form 
and a TImage in the form that contains a picture.
}
procedure TForm1.Button1Click(Sender: TObject);
begin
  PaintBox1.Canvas.Draw(0,0, Image1.Picture.Graphic);
end;
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!