2016-08-01 81 views
3

我想采取屏幕的特定部分的屏幕截图。这里是来“切割”我想在屏幕部分的坐标:采取屏幕的特定部分的屏幕截图

左:442 上衣:440 右:792 底部:520

也就是说,宽度为350像素和高度的矩形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; 
+0

http://stackoverflow.com/questions/8360368/how-to-use-copyrect-method-in-delphi – fantaghirocco

回答

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); 

你的代码的其余似乎是正确的。

+0

非常感谢你:) – delphirules