C # leverages Windows self-gdi32.dll to implement a capture screen feature instance

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.