自定义截图函数
function TForm1.CaptureForm(HWND: THandle; W, H: Integer): TBitmap;
var
TmpBitmap: TBitmap;
TmpCanvas: TCanvas;
DC: HDC;
begin
TmpBitmap := TBitmap.Create;
TmpBitmap.Width := W;
TmpBitmap.Height := H;
DC := GetWindowDC(HWND);
TmpCanvas := TCanvas.Create;
TmpCanvas.Handle := DC;
TmpBitmap.Canvas.CopyRect(
Rect(0, 0, W, H),
TmpCanvas,
Rect(0, 0, W, H));
TmpCanvas.Free;
ReleaseDC(0, DC);
Result := TmpBitmap;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
jpg:TJPEGImage;
begin
jpg:= TJPEGImage.Create;
jpg.CompressionQuality:=100;
jpg.Assign(CaptureForm(Handle, 500, 500));
jpg.SaveToFile(‘D:\1.jpg‘);
ShowMessage(‘扑抓图片成功!‘);
end;
时间: 2024-10-23 15:19:55