Copy part of one image to another

Posted in Graphics

You may use CopyRect function for copying part of one canvas to another.

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    Image1.Picture.LoadFromFile(OpenDialog1.FileName);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Image2.Canvas.CopyRect(
    Rect(0,0,Image2.Width,Image2.Height),
    Image1.Canvas,
    Rect(
      0,
      0,
      Image1.Picture.Width-50,
      Image1.Picture.Height-50));
end;