CopyMode (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example uses the CopyMode of an image's canvas to whiten and empty 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.

Code

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;

Uses

See Also

Personal tools
Assistance