我正在尝试对屏幕的特定部分进行截图。下面是我想要“剪切”的屏幕部分的坐标:
左: 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;发布于 2016-08-01 21:48:29
你在这里所做的是复制整个屏幕,并在你的新位图中的坐标Rect(442,440,792,520);处绘制它。这不是它的画布。
坐标Rect(442,440,792,520)对应于要从源位图中获取的零件。您希望将其复制到新位图中,因此在rect Rect(0,0,350,80)中
你可以像这样简单地调整你的rect:
rect_source := Rect(442,440,792,520);
rect_destination := Rect(0,0,350,80);您的其余代码看起来是正确的。
https://stackoverflow.com/questions/38700163
复制相似问题