Take a screenshot of a particular area in Delphi 7

南楼画角 提交于 2019-12-13 03:46:56

问题


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 ?


回答1:


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
      );
      Image1.Picture.Bitmap.Assign(bitmap);
      // bitmap.SaveToFile('c:\filename.bmp');
    finally
      ReleaseDC(panel1.Handle, dc);
    end;
  finally
    bitmap.Free;
  end;
end;

Hope that helps.



来源:https://stackoverflow.com/questions/46986458/take-a-screenshot-of-a-particular-area-in-delphi-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!