RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCanvas.CopyMode Property

Specifies how a graphical image is copied onto the canvas.

Pascal
property CopyMode: TCopyMode;
C++
__property TCopyMode CopyMode;

Set CopyMode to affect the way graphical images are drawn onto the canvas. The CopyMode is used when copying an image from another canvas using the CopyRect method. CopyMode is also used by TBitmap objects when they draw themselves to a canvas. 

Use CopyMode to achieve a variety of affects when rendering an image. Achieve special effects like merged images and making parts of a bitmap transparent by combining multiple images with different CopyModes.  

C++ Examples: 

 

/*
The following example uses the CopyMode of an image’s canvas
to blank out the image when the user chooses the "Cut" menu
item.  This example requires a Main menu with a Copy and a
Cut menu item that have their OnClick error handlers populated.
Note: CopyMode and CopyRect are members of the destination
canvas.
*/
void __fastcall TForm1::Copy1Click(TObject *Sender)
{
    TRect SrcRect, DstRect;
    Image2->Canvas->CopyMode = cmSrcCopy;
    DstRect = Rect(0, 0, Image2->Width, Image2->Height);
    SrcRect = Rect(0, 0, Image1->Width, Image1->Height);
    Image2->Canvas->CopyRect(DstRect, Image1->Canvas, SrcRect);
}

void __fastcall TForm1::Cut1Click(TObject *Sender)
{
 TRect r;
 Copy1Click(Sender); // Do the same thing as the copy menu item.
 Image1->Canvas->CopyMode = cmWhiteness;
 r = Rect(0, 0, Image1->Width, Image1->Height);
 Image1->Canvas->CopyRect(r, Image1->Canvas, r);
 Image1->Canvas->CopyMode = cmSrcCopy; // Restore the copy mode.
}

 

Delphi Examples: 

{
The following example uses the CopyMode of an image’s canvas
to blank out the image when the user chooses the "Cut" menu 
item.  This example requires a Main menu with a Copy and a
Cut menu item that have their OnClick error handlers populated.
Note: CopyMode and CopyRect are members of the destination
canvas.
}
procedure TForm1.Copy1Click(Sender: TObject);
var
  DstRect, SrcRect: TRect;
begin
  with Image2.Canvas do
  begin
    CopyMode := cmSrcCopy;
    DstRect := Rect(0, 0, Image2.Width, Image2.Height);
    SrcRect := Rect(0, 0, Image1.Width, Image1.Height);
    CopyRect(DstRect, Image1.Canvas, SrcRect);
  end;
end;

procedure TForm1.Cut1Click(Sender: TObject);
var
  ARect: TRect;
begin
  Copy1Click(Sender); { do the same thing as the copy menu item }
  with Image1.Canvas do
  begin
    CopyMode := cmWhiteness;
    ARect := Rect(0, 0, Image1.Width, Image1.Height);
    CopyRect(ARect, Image1.Canvas, ARect);
    CopyMode := cmSrcCopy; { restore the copy mode }
  end;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!