截取屏幕特定部分的屏幕截图

del*_*les 3 delphi delphi-2007 delphi-xe

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

左: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;
Run Code Online (Sandbox Code Playgroud)

Ken*_*ssa 7

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

坐标Rect(442,440,792,520)对应于要从源位图获取的部分.你想将它复制到你的新位图"内部",所以在rect中Rect(0,0,350,80)

您可以像这样调整矩形:

 rect_source := Rect(442,440,792,520);
 rect_destination := Rect(0,0,350,80);
Run Code Online (Sandbox Code Playgroud)

其余的代码似乎是正确的.