Question

I am using Lazarus and I have a TImage inside a form. The black table is a TImage and the numbers are labels. I need to take a screenshot of the red area I drew.

enter image description here

How can I perform this?

I have Lazarus 1.0.14 and I didn't find any example about this. Any suggestion?

Was it helpful?

Solution

This is a painful design, but well, one simple way might be to put all the controls on a common container and copy its canvas to a bitmap. The following example assumes, that you have put your image and all the labels on a common TPanel control (Panel1):

procedure TForm1.Button1Click(Sender: TObject);
var
  R: TRect;
  Bitmap: TBitmap;
begin
  Bitmap := TBitmap.Create;
  try
    R := Rect(0, 0, Panel1.Width, Panel1.Height);
    Bitmap.SetSize(Panel1.Width, Panel1.Height);
    Bitmap.Canvas.CopyRect(R, Panel1.Canvas, R);
    Bitmap.SaveToFile('C:\Screenshot.bmp');
  finally
    Bitmap.Free;
  end;
end;

OTHER TIPS

You can use GetFormImage to get the form image, and keep the part that corresponds to your image area in it:

var
  Bmp: TBitmap;
begin
  Bmp := GetFormImage;
  try
    Bmp.Canvas.CopyRect(Image1.ClientRect, Bmp.Canvas, Image1.BoundsRect);
    Bmp.SetSize(Image1.Width, Image1.Height);
    Bmp.SaveToFile('....');
  finally
    Bmp.Free;
  end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top