雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

Delphi

當(dāng)前位置:主頁 > 軟件編程 > Delphi >

Delphi實(shí)現(xiàn)截屏存盤的方法

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:Delphi|點(diǎn)擊:

本文實(shí)例講述了Delphi實(shí)現(xiàn)截屏存盤的方法。分享給大家供大家參考。具體分析如下:

該實(shí)例可實(shí)現(xiàn)截取屏幕,并保存為JPEG文件格式的功能。

procedure TForm1.ScreenCap(LeftPos,TopPos,RightPos,BottomPos:integer);
var
 RectWidth,RectHeight:integer;
 SourceDC,DestDC,Bhandle:integer;
 Bitmap:TBitmap;
 MyJpeg: TJpegImage;
 Stream:TMemoryStream;
begin
 MyJpeg:= TJpegImage.Create;
 RectWidth:=RightPos-LeftPos;
 RectHeight:=BottomPos-TopPos;
 SourceDC:=CreateDC('DISPLAY','','',nil);
 DestDC:=CreateCompatibleDC(SourceDC);
 Bhandle:=CreateCompatibleBitmap(SourceDC,
 RectWidth,RectHeight);
 SelectObject(DestDC,Bhandle);
 BitBlt(DestDC,0,0,RectWidth,RectHeight,SourceDC,
 LeftPos,TopPos,SRCCOPY);
 Bitmap:=TBitmap.Create;
 Bitmap.Handle:=BHandle;
 Stream := TMemoryStream.Create;
 Bitmap.SaveToStream(Stream);
 Stream.Free;
 try
  MyJpeg.Assign(Bitmap);
  MyJpeg.CompressionQuality:=70;
  MyJpeg.Compress;
  MyJpeg.SaveToFile('C:MyJPEGImage.JPG');
 finally
  MyJpeg.Free;
  Bitmap.Free;
  DeleteDC(DestDC);
  ReleaseDC(Bhandle,SourceDC);
 end;
end;

希望本文所述對(duì)大家的Delphi程序設(shè)計(jì)有所幫助。

上一篇:Delphi 在窗體上創(chuàng)建自己光標(biāo)的實(shí)例

欄    目:Delphi

下一篇:Delphi 用DLL實(shí)現(xiàn)插件的簡(jiǎn)單實(shí)例

本文標(biāo)題:Delphi實(shí)現(xiàn)截屏存盤的方法

本文地址:http://www.jygsgssxh.com/a1/Delphi/8602.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有