The example of this paper describes the use of Windows Gdi32.dll to implement the capture screen function, is a C # application design is a very useful function, is now shared for everyone for reference.
The specific function code is as follows:
internal static void Getscreenshot () {//Gets the current screen size Rectangle rect = new Rectangle (); Rect = Screen.allscreens[0]. Workingarea; Calculate the size of the picture because the length and width of the picture may exceed the current screen size//Create an image with the current screen as the template control ctl = new control (); Graphics G1 = ctl. CreateGraphics (); Creates a bitmap with a screen size of Image myimage = new Bitmap (rect. Width, Rect. Height, G1); Graphics g2 = Graphics.fromimage (myimage); Get the screen DC IntPtr DC1 = G1. GetHdc (); Get bitmap dc IntPtr DC2 = G2. GetHdc (); Call this API function to implement screen capture BitBlt (DC2, 0, 0, rect. Width, Rect. Height, DC1, 0, 0, 13369376); Release the DC G1 of the screen. RELEASEHDC (DC1); Release the bitmap DC G2. RELEASEHDC (DC2); Save//image.getthumbnailimageabort Mycallback = new Image.getthumbnailimageabort (thumbnailcallback) in JPG file format; Return Myimage.getthumbnailimage (control. Width, control. Height, Mycallback, IntPtr.Zero); Myimage.save ("D:\\aa.jpg");} [System.Runtime.InteropServices.DllImportAttribute ("Gdi32.dll")]private static extern bool BitBlt (INTPTR hdcdest,// Handle of the target device int nxdest,//The x-coordinate of the upper-left corner of the target object int nydEST,//The x-coordinate of the upper-left corner of the target object, int nwidth,//width of the target object's rectangle int nheight,//The length of the target object's rectangle IntPtr hdcsrc,//handle of the source device int NXSRC,/ /The x-coordinate of the upper-left corner of the source object is int nysrc,//The x-coordinate of the upper-left corner of the source object System.Int32 dwrop//raster operation value);
It is hoped that the C # Crawl screen example in this paper will help everyone in C # programming.
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
C # leverages Windows self-gdi32.dll to implement a capture screen feature instance
This address: http://www.paobuke.com/develop/c-develop/pbk23610.html
Related content on the inheritance of C # class The difference between array, ArrayList, and List in C # The method of setting up the software to run automatically (modify the registry) WinForm simple Cache class instance
Ó? C#?? Í??? ±£′?? Áoracle BLOBX???? Dμ?? ¨c# How to manipulate Windows Registry C # Implements a class instance for manipulating a WAV sound file C # real-World Video Address resolution (2014 New algorithm)
C # leverages Windows self-gdi32.dll to implement a capture screen feature instance