C # screenshot Operation Method Daquan

Source: Internet
Author: User

usingSystem.Drawing;usingSystem.Windows.Forms;namespacewindowsformsapplication1{classScreencapture {PrivateBitmap _screenshot =NULL; /// <summary>        ///Capture Full Screen/// </summary>        /// <returns>return value</returns>         PublicBitmap Capturescreen () {returnCapture (Rectangle.empty,false); }         /// <summary>        ///capture full screen and save/// </summary>        /// <param name= "FileName" >file path</param>        /// <returns></returns>         PublicBitmap Capturescreen (stringfileName) {Bitmap screenshot= Capture (Rectangle.empty,false);            SaveImage (FileName, screenshot); returnscreenshot; }         /// <summary>        ///screenshot to shear plate/// </summary>         Public voidCopyToClipboard () {if( This. _screenshot! =NULL) Clipboard.setimage ( This. _screenshot); Else if( This. _screenshot = =NULL) MessageBox.Show ("No screenshot found. Please take a screenshot first.","Copy to Clipboard"); }         /// <summary>        ///Area Screen Cutting/// </summary>        /// <param name= "rect" >Area Range</param>        /// <returns>return value</returns>         PublicBitmap capturerectangle (Rectangle rect) {returnCapture (Rect,true); }         /// <summary>        ///Area Screen Cutting/// </summary>        /// <param name= "rect" >Area Range</param>        /// <param name= "FileName" >file path</param>        /// <returns>return value</returns>         PublicBitmap Capturerectangle (Rectangle rect,stringfileName) {Bitmap screenshot= Capture (Rect,true);            SaveImage (FileName, screenshot); returnscreenshot; }         PrivateBitmap Capture (Rectangle rect,BOOLisrect) {            intScreenWidth =Screen.PrimaryScreen.Bounds.Width; intScreenHeight =Screen.PrimaryScreen.Bounds.Height; Bitmap screenshot=NULL; if(!isrect) screenshot=NewBitmap (ScreenWidth, screenheight); Else if(isrect) screenshot=NewBitmap (rect. Width, Rect.             Height); Graphics g=Graphics.fromimage (screenshot); if(!isrect) {G.copyfromscreen (Point.empty, Point.empty, screenshot.            Size); }            Else if(isrect) {G.copyfromscreen (NewPoint (Rect. X, Rect. Y), Point.empty, rect.            Size); }              This. _screenshot =screenshot; returnscreenshot; }         Private voidSaveImage (stringFileName, Bitmap screenshot) {            stringext =System.IO.Path.GetExtension (fileName);; Ext=ext.             ToLower (); if(ext = =". jpg"|| ext = =". JPEG") screenshot.            Save (FileName, System.Drawing.Imaging.ImageFormat.Jpeg); Else if(ext = =". gif") screenshot.            Save (FileName, System.Drawing.Imaging.ImageFormat.Gif); Else if(ext = =". PNG") screenshot.            Save (FileName, System.Drawing.Imaging.ImageFormat.Png); Else if(ext = =". bmp") screenshot.            Save (FileName, SYSTEM.DRAWING.IMAGING.IMAGEFORMAT.BMP); Else if(ext = =". TIFF") screenshot.        Save (FileName, System.Drawing.Imaging.ImageFormat.Tiff); }    }}

C # Operations Methods Daquan

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.