全部分数了-全屏截图 (20分)

  • 主题发起人 主题发起人 xinux11
  • 开始时间 开始时间
X

xinux11

Unregistered / Unconfirmed
GUEST, unregistred user!
我最近在编一个全屏截图程序,可以实现全屏截图,可是每次截图时的CPU占用率在30以上,而我现在在DFW上找一个高手的程序,它也能全屏截图,可以截图时候,基本上不占用CPU,请问这是怎么回事啊?

以下是我截图的代码:
Fullscreen:=TBitmap.Create;//创建一个BITMAP来存放图象
DC:=GetDC(0);//取得屏幕的DC,参数0指的是屏幕
FullscreenCanvas := TCanvas.Create;//创建一个CANVAS对象
FullscreenCanvas.Handle := DC;
Fullscreen.Width := Screen.Width;
Fullscreen.Height := Screen.Height;
Fullscreen.Canvas.CopyRect
(Rect(0,0,Screen.Width,Screen.Height),FullScreenCanvas,
Rect(0,0,Screen.Width,Screen.Height));
ReleaseDC(0,DC);
Fullscreen.Canvas.free;
FullScreen.free;

以下是这个抓图占用CPU很少的软件,它本身是一个用于背单词的软件,不过里面的带了一个小工具可以全屏截图,那个截图功能不知道怎么才能占这么少的CPU。
http://qqbdc.nease.net/download/QQBDCInstall.exe
 
分数不多,但是急啊!!!!!!
 
没有人了吗?
 
哎..........
 
截屏
var ss:tcanvas;
begin
ss:=tcanvas.Create;
ss.Handle:=getdc(0);
bitblt(image1.canvas.handle,0,0,image1.width,image1.height,ss.handle,0,0,srccopy);
end;

 
var
bmp:TBitmap;
r:TRect;
begin
bmp := TBitmap.Create;
bmp.Width := PaintBox1.Width;
bmp.Height := PaintBox1.Height;
r:=Rect(Paintbox1.Left,Paintbox1.Top,Paintbox1.Width,Paintbox1.Height);
PaintBox1.Canvas.MoveTo(0,0);
PaintBox1.Canvas.LineTo(Paintbox1.Width,Paintbox1.Height);
PaintBox1.Canvas.Ellipse(10,10,120,140);
try
bmp.Canvas.CopyRect(R,PaintBox1.Canvas,R);
bmp.SaveToFile('c:/AA.bmp');
finally
bmp.Free;
end;
 
建议你不要每次都创建Tcanvas和TBitmap对象,而是在程序初始化的时候,去生成,这样就会减少很多CPU和内存操作。
 
用了wqhatnet的方法,截图果然只用很少的资料了,可是我保存成图片的时候CPU却要用到30以上,有什么方法让保存图片时候的CPU占用率降低吗
 
unit ScrnCap;

interface
uses WinTypes, WinProcs, Forms, Controls, Classes, Graphics;

type
TScrnCap = class
private
{ Private declarations }
public
{ Public declarations }
function CaptureScreenRect( ARect: TRect ): TBitmap;
function CaptureScreen: TBitmap;
function CaptureClientImage( Control: TControl ): TBitmap;
function CaptureControlImage( Control: TControl ): TBitmap;
function CaptureWindowImage( Wnd: HWND ): TBitmap;
end;

implementation

{ Use this to capture a rectangle on the screen... }
function TScrnCap.CaptureScreenRect( ARect: TRect ): TBitmap; //TRect defines a rectangle.
var
ScreenDC: HDC; //device context (DC)
begin
Result := TBitmap.Create;
with Result, ARect do
begin
Width := Right - Left;
Height := Bottom - Top;
ScreenDC := GetDC( 0 );
try
BitBlt( Canvas.Handle, 0, 0, Width, Height, ScreenDC,
Left, Top, SRCCOPY );
finally
ReleaseDC( 0, ScreenDC );
end;
end;
end;

{ Use this to capture the entire screen... }
function TScrnCap.CaptureScreen: TBitmap;
begin
with Screen do
Result := CaptureScreenRect( Rect( 0, 0, Width, Height ));
end;

{ Use this to capture just the client area of a form or control... }
function TScrnCap.CaptureClientImage( Control: TControl ): TBitmap;
begin
with Control, Control.ClientOrigin do
Result := CaptureScreenRect( Bounds( X, Y, ClientWidth,
ClientHeight ));
end;

{ Use this to capture an entire form or control... }
function TScrnCap.CaptureControlImage( Control: TControl ): TBitmap;
begin
with Control do
if Parent = nil then
Result := CaptureScreenRect( Bounds( Left, Top, Width,
Height ))
else
with Parent.ClientToScreen( Point( Left, Top )) do
Result := CaptureScreenRect( Bounds( X, Y, Width,
Height ));
end;

{ Use this to capture an entire form or control paased as an API hWnd... }
function TScrnCap.CaptureWindowImage( Wnd: HWND ): TBitmap;
var
R: TRect;
begin
GetWindowRect(Wnd, R);
Result := CaptureScreenRect(R);
end;

end.
 

Similar threads

I
回复
0
查看
593
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部