This paper illustrates the method of Delphi to save the screen. Share to everyone for your reference. The specific analysis is as follows:
This instance implements the interception screen and saves the functionality as a JPEG file format.
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
I hope this article will help you with the Delphi program design.