Delphi完成截屏存盤的辦法。本站提示廣大學習愛好者:(Delphi完成截屏存盤的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是Delphi完成截屏存盤的辦法正文
本文實例講述了Delphi完成截屏存盤的辦法。分享給大家供大家參考。詳細剖析如下:
該實例可完成截取屏幕,並保管為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;
希望本文所述對大家的Delphi順序設計有所協助。