C # save Form as Picture (save profile views)

Source: Internet
Author: User

The source code is as follows:

     #region Save profile private void Button_save_click (object sender, EventArgs e) {SaveFileDialog s            Aveimagedialog = new SaveFileDialog ();            Saveimagedialog.title = "Save profile views";            Saveimagedialog.defaultext = ". png";            Saveimagedialog.filename = linefeaturelayer.name + "profile views";            Saveimagedialog.initialdirectory = "c:\\";            DialogResult dr = Saveimagedialog.showdialog ();                if (Dr==dialogresult.ok) {captureimage (saveimagedialog.filename); MessageBox.Show ("Saved successfully!            ");                }} private void Captureimage (string path) {try {//Get the current screen size                Rectangle rect = new Rectangle ();                Rect = Screen.getworkingarea (this); Create an image with the current screen as a template graphics G1 = this.                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 Myimage.save (Path, imageformat.png) in JPG file format; } catch (System.Exception ex) {MessageBox.Show (ex. Message + "Save picture Failed!"             "); }}//Declare an API function [System.Runtime.InteropServices.DllImportAttribute ("Gdi32.dll")] Private static extern bool BitBlt (INTPTR hdcdest,//Handle of the target DC int nxdest, int nyde St, int nwidth, int nheight, IntPtr hdcsrc,//Handle of source DC           int nxsrc, int nysrc, System.Int32 dwrop//raster processing value); #endregion



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.