【问题标题】:Take screenshot of specific part of screen截取屏幕特定部分的屏幕截图
【发布时间】:2016-08-01 13:27:25
【问题描述】:

我正在尝试截取屏幕特定部分的屏幕截图。这是我要“剪切”的屏幕部分的坐标:

左:442 顶部:440 右:792 底部:520

也就是一个宽350px,高80px的矩形。但我不知道如何使用 CopyRect 来完成这项任务,而是得到一个空白图像。这是我的代码:

function screenshot: boolean;
var
  Bild : TBitmap;
  c: TCanvas;
  rect_source, rect_destination : TRect;
begin
   c := TCanvas.Create;
   bild := tbitmap.Create;
   c.Handle := GetWindowDC(GetDesktopWindow);
   try
     rect_source := Rect(0, 0, Screen.Width, Screen.Height);
     rect_destination := Rect(442,440,792,520);
     Bild.Width := 350;
     Bild.Height := 80;
     Bild.Canvas.CopyRect(rect_destination, c, rect_source);
     Bild.savetofile('c:\users\admin\desktop\screen.bmp');
   finally
    ReleaseDC(0, c.Handle);
     Bild.free;
     c.Free;
   end;
end;

【问题讨论】:

标签: delphi delphi-xe delphi-2007


【解决方案1】:

您在这里所做的是复制整个屏幕并在新位图中的坐标Rect(442,440,792,520); 处绘制它...它不在画布上。

坐标Rect(442,440,792,520) 对应于您要从源位图中获取的部分。你想把它复制到你的新位图“里面”,所以在矩形Rect(0,0,350,80)

你可以像这样简单地调整你的矩形:

 rect_source := Rect(442,440,792,520);
 rect_destination := Rect(0,0,350,80);

您的其余代码似乎正确。

【讨论】:

    猜你喜欢
    • 2015-03-14
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-26
    相关资源
    最近更新 更多