用TimageList元件实现屏幕捕捉器
Timagelist元件的构造CreateSize用于创建一上图像列表并指定图像的尺寸设为与获得整个桌面的句柄,程序示例如下:
Var DeakTopCanvas:Tcanvas;屏幕一产大,程序示例如下:
imagelist1.createsize(screen.width,screen.height);
DeakTopCanvas:=TCanvas.create;
deaktopcanvas.handle:=getdc(hwnd_desktop);
Hwnd_Desktop是一个预定义的常量代表整个桌面。程序示例如下:
Var
BitMap:TBitMap;
with bitmap do
begin
width:=screen.width;
height:=screen.height;
canvas.copyrect(canvas.cliprect,deaktopcanvas,deaktopcanvas.cliprect);
imagelist1.add(bitmap,nil);
ReleaseDC(Handle,Hwnd_DeskTop);
Free;
End;
BrushCopy, CopyRect Example
The following code illustrates the differences between CopyRect and BrushCopy. The bitmap graphic 慣ARTAN.BMP is loaded into Bitmap and displayed on the Canvas of Form1. BrushCopy replaces the color black in the graphic with the brush of the canvas, while CopyRect leaves the colors intact.
var
Bitmap: TBitmap;
MyRect, MyOther: TRect;
begin
MyRect := Rect(10,10,100,100);
MyOther := Rect(10,111,100, 201);
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile('c:/windows/tartan.bmp');
Form1.Canvas.BrushCopy(MyRect, Bitmap, MyRect, clBlack);
Form1.Canvas.CopyRect(MyOther,Bitmap.Canvas,MyRect);
Bitmap.Free;
end;