I have a panel in the form delphi that contains pictures, labels and others. I need to take screenshots in the panel area. How can I perform this ?
Asked
Active
Viewed 2,122 times
1 Answers
2
Assuming that you have a panel named Panel1 to be screenshot, a button named Button1 to do the screen shoot, and Image1 to display the screenshot, here is simple code you can use:
procedure TForm1.Button3Click(Sender: TObject);
var
bitmap: TBitmap;
dc: HDC;
begin
bitmap := TBitmap.Create();
try
dc := GetDC(Panel1.Handle);
try
bitmap.Width := Panel1.Width;
bitmap.Height := Panel1.Height;
BitBlt(
bitmap.Canvas.Handle, 0, 0, Panel1.Width, Panel1.Height,
dc, 0, 0,
SRCCOPY
);
// copy the screenshot to an image
Image1.Picture.Bitmap.Assign(bitmap);
// copy the screenshot to the clipboard
Clipboard.Assign(bitmap);
// save the screenshot to a file
bitmap.SaveToFile('c:\filename.bmp');
finally
ReleaseDC(panel1.Handle, dc);
end;
finally
bitmap.Free;
end;
end;
Hope that helps.

stevenvh
- 2,971
- 9
- 41
- 54

Buyut Joko Rivai
- 188
- 2
- 6
-
Terima Kasih om benar" sesuai yang diinginkan – Onewtan Oct 29 '17 at 01:12
-
Sip sip. Sama-sama. – Buyut Joko Rivai Oct 30 '17 at 03:17