RAD Studio VCL Reference
|
Renders the graphic specified by the Graphic parameter on the canvas at the location given by the coordinates (X, Y).
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); }
/* 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:
{ 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) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|