The source code is as follows:
# Region Save the profile private void button_save_Click (object sender, EventArgs e) {SaveFileDialog saveImageDialog = new SaveFileDialog (); saveImageDialog. title = "Save profile chart"; saveImageDialog. defaultExt = ". png "; saveImageDialog. fileName = Linefeaturelayer. name + "profile chart"; saveImageDialog. initialDirectory = "C: \"; DialogResult dr = saveImageDialog. showDialog (); if (dr = DialogResult. OK) {CaptureImage (saveImage Dialog. FileName); MessageBox. Show ("saved successfully! ") ;}} Private void CaptureImage (string path) {try {// obtain the current Screen size Rectangle rect = new Rectangle (); rect = Screen. getWorkingArea (this); // create an image Graphics g1 = this with the current screen as the template. createGraphics (); // create a screen size-based Bitmap Image MyImage = new Bitmap (rect. width, rect. height, g1); Graphics g2 = Graphics. fromImage (MyImage); // obtain the DC IntPtr dc1 = g1.GetHdc (); // obtain the DC IntPtr dc2 = g2.GetHdc () of Bitmap; // call this API function to implement the screen Capture BitBlt (dc2, 0, 0, rect. width, rect. height, dc1, 0, 0, 13369376); // release the DC g1.ReleaseHdc (dc1) on the screen; // release the DC g2.ReleaseHdc (dc2) of Bitmap ); // save MyImage in JPG format. save (path, ImageFormat. png);} catch (System. exception ex) {MessageBox. show (ex. message + "An error occurred while saving the image! ") ;}} // Declare an API function [System. runtime. interopServices. dllImportAttribute ("gdi32.dll")] private static extern bool BitBlt (IntPtr hdcDest, // int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, // source DC handle int nXSrc, int nYSrc, System. int32 dwRop // The processing value of the grating); # endregion
: