procedure Get_Form_Image(aform: TForm); //拷贝屏幕图像Var abitmap: Tbitmap; acanvas: Tcanvas; DC: hdc; L, T: Integer; isfull, isjpg, isopen: Boolean; apath, aopen: String; ajpg: TJpegimage;Begin isfull := False;//是否全屏 isjpg := False;//保存为JPG? isopen:= True;//立即打开 aopen := 'mspaint.exe'; //打开方式 apath := Format('c:/%s',[aform.Caption]); //保存路径 aform.Update; SetFocus(aform.Handle); //Form置顶后,才能截图。 aform.Update; abitmap := TBitmap.Create; acanvas := TCanvas.Create; DC := Windows.Getdc(0); With aform Do Try acanvas.Handle := DC; If Not isfull Then //不需要全屏,只是当前Form Begin abitmap.Width := Width; abitmap.Height := Height; L := left; T := top; abitmap.Canvas.CopyRect(rect(0, 0, Width, Height), acanvas, rect(L, T, Width + L, Height + T)); End Else //全屏 Begin abitmap.Width := screen.Width; abitmap.Height := screen.Height; abitmap.Canvas.CopyRect(rect(0, 0, screen.Width, screen.Height), acanvas, rect(0, 0, screen.Width, screen.Height)); End; If isjpg Then Begin //BMP压缩成JPG 再保存。 apath := ChangeFileExt(apath, '.jpg'); ajpg := TJpegimage.Create; Try ajpg.Assign(abitmap); {将BMP图象转成JPG格式,便于在互联网上传输} ajpg.CompressionQuality := 75; {JPG文件压缩百分比设置,数字越大图像月清晰,数据越大。默认=75} ajpg.SaveToFile(apath); Finally FreeAndNil(aJpg); End; End Else //BMP 直接保存。 Begin apath := ChangeFileExt(apath, '.bmp'); abitmap.savetofile(apath); End; apath := ExtractShortPathName(apath); {修改成短路径,防止出现带空格的路径} //打开文件 If isopen And FileExists(apath) And (Length(aopen) > 0) Then ShellExecute(aform.Handle, 'open', PChar(aopen), PChar(apath), '', SW_SHOW); Finally acanvas.Free; releasedc(0, DC); abitmap.Free; End;End;procedure TForm1.BitBtn1Click(Sender: TObject);begin Get_Form_Image(self);end;