屏幕截图,为什么截不到鼠标指针?(40分)

  • 主题发起人 主题发起人 zggsbd
  • 开始时间 开始时间
Z

zggsbd

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Timer1Timer(Sender: TObject);

var
Fullscreen:Tbitmap;
FullscreenCanvas:TCanvas;
dc:HDC;

begin
Fullscreen := TBitmap.Create; // 创建一个 BITMAP 来存放图象
Fullscreen.Width := screen.width;
Fullscreen.Height := screen.Height;
DC := GetDC (0); // 取得屏幕的 DC,参数 0 指的是屏幕
FullscreenCanvas := TCanvas.Create; // 创建一个 CANVAS 对象
FullscreenCanvas.Handle := DC;
Fullscreen.Canvas.CopyRect(Rect (0, 0, screen.Width, screen.Height),
fullscreenCanvas,Rect (0, 0, Screen.Width, Screen.Height));// 把整个屏幕复制到 BITMAP 中

FullscreenCanvas.Free; // 释放 CANVAS 对象

ReleaseDC (0, DC); // 释放 DC

//*******************************

image1.picture.Bitmap:=fullscreen;// 拷贝下的图象赋给 IMAGE 对象
image1.Width:=fullscreen.Width;
image1.Height:=fullscreen.Height;

fullscreen.free; // 释放 bitmap

end;

屏幕截图,为什么截不到鼠标指针(小箭头)?
 
要另外画上鼠标指针,我看过这个代码,但是忘了[:(]
 
鼠标要另外画的
 
获取鼠标当前位置,画就行了
 
{ uses
Windows, Classes, Graphics, Jpeg; }

//************ Capture .bmp screen ***************************
Function ScrBmp : TBitmap;
Var
Bit : TBitmap;
Canv : TCanvas;
Rec : TRect;
X, Y : Integer;
begin
Canv := TCanvas.Create;
Canv.Handle := GetDC(GetDeskTopWindow);
X := GetSystemMetrics(SM_CXSCREEN);
Y := GetSystemMetrics(SM_CYSCREEN);
Try
Bit := TBitmap.Create;
Bit.Width := X;
Bit.Height := Y;
Rec := Rect(0, 0, X, Y);
Bit.Canvas.CopyRect(Rec, Canv, Rec);
Finally
ReleaseDC(0, Canv.Handle);
end;
Result := Bit;
end;
//************* End of .Bmp Capture *************************

//*************** Draw Cursor on the bitmap ******************
Function DrawCursor(Bit : TBitmap) : TBitmap;
Var
Cur : TCursorInfo;
Icn : TIcon;
IcnInfo : TIconInfo;
Rec : TRect;
begin
Icn := TIcon.Create;
Rec := Bit.Canvas.ClipRect;
try
Cur.cbSize := SizeOf(Cur);
if GetCursorInfo(Cur) then
if Cur.flags = CURSOR_SHOWING then
begin
Icn.Handle := CopyIcon(Cur.hCursor);
if GetIconInfo(Icn.Handle, IcnInfo) then
Bit.Canvas.Draw(Cur.ptScreenPos.X - Integer(IcnInfo.XHotSpot) - Rec.Left,
Cur.ptScreenPos.Y - Integer(IcnInfo.YHotSpot) - Rec.Top,
Icn);
end;
finally
Icn.Free;
end;
Result := Bit;
end;
//************ End of cursor drawing *************************

//********** Convert to jpg function *************************
Function Bmp2Jpg(Bit : TBitmap; Quality : Integer) : TJpegImage;
Var
Jpg : TJpegImage;
begin
try
Jpg := TJpegImage.Create;
Jpg.CompressionQuality := Quality;
Jpg.Compress;
Jpg.Assign(Bit);
finally
Bit.Free;
end;
Result := Jpg;
end;
//************* End of JPG ***********************************

//*********** Function to call when saving *******************
Function SaveScr(Quality : Integer; IncMouse : Boolean; SavAs : String) : Boolean;
begin
If IncMouse then
Bmp2Jpg(DrawCursor(ScrBmp), Quality).SaveToFile(SavAs)
else
Bmp2Jpg(ScrBmp, Quality).SaveToFile(SavAs);

If FileExists(SavAs) then
Result := True
else
Result := False;
end;
//************* End of call function *************************

to use it call the SaveScr function as follows :


Code:
SaveScr(100, True, 'Screen.Jpg') //Quality could be between 0 - 100
 
后退
顶部