/// <summary> /// Creator, set format handler /// </summary> /// <param name="formatHandler">The format handler instance</param> public ScreenCapture( ImageFormatHandler formatHandler ) { doc.PrintPage += new PrintPageEventHandler( printPage ); this.formatHandler = formatHandler; }
/// <summary> /// Save all captured screens into a file. /// </summary> /// <param name="filename">The name of the target file. The extension in there is ignored, /// it will replaced by an extension derived from the desired file format.</param> /// <param name="format">The format of the file.</param> /// <returns>An array of images captured.</returns> public virtual void Save( String filename, ImageFormatHandler.ImageFormatTypes format ) { String directory = Path.GetDirectoryName( filename ); String name = Path.GetFileNameWithoutExtension( filename ); String ext = Path.GetExtension( filename ); ext = formatHandler.GetDefaultFilenameExtension( format ); if ( ext.Length == 0 ) { format = ImageFormatHandler.ImageFormatTypes.imgPNG; ext = "png"; } try { ImageCodecInfo info; EncoderParameters parameters = formatHandler.GetEncoderParameters( format, out info ); for ( int i = 0; i < images.Length; i++ ) { if ( images.Length > 1 ) { filename = String.Format( "{0}\\{1}.{2:D2}.{3}", directory, name, i + 1, ext ); } else { filename = String.Format( "{0}\\{1}.{2}", directory, name, ext ); } image = images[i]; if ( parameters != null ) { image.Save( filename, info, parameters ); } else { image.Save( filename, ImageFormatHandler.GetImageFormat( format ) ); } } } catch ( Exception ex ) { string s = string.Format("Saving image to [{0}] in format [{1}].\n{2}", filename, format.ToString(), ex.ToString() ); MessageBox.Show( s, "Capture failed", MessageBoxButtons.OK, MessageBoxIcon.Error ); } }
/// <summary> /// Creator /// </summary> public ScreenCapture() { doc.PrintPage += new PrintPageEventHandler( printPage ); formatHandler = new ImageFormatHandler(); }
/// <summary> /// Capture a specific control in the client area of a form. /// </summary> /// <param name="window">This is a control which should be captured.</param> /// <param name="filename">The name of the target file. The extension in there is ignored, /// it will replaced by an extension derived from the desired file format.</param> /// <param name="format">The format of the file.</param> /// <returns>The image which has been captured.</returns> public virtual Bitmap CaptureControl( Control window, String filename, ImageFormatHandler.ImageFormatTypes format ) { CaptureControl( window ); Save( filename, format ); return images[0]; }
/// <summary> /// Capture the screen and save it into a file, which portion of the screen is captured /// is defined by <paramref name="typeOfCapture"/>. /// </summary> /// <param name="typeOfCapture">Selects, what is actually captured, see <see cref="CaptureType"/>.</param> /// <param name="filename">The name of the target file. The extension in there is ignored, /// it will replaced by an extension derived from the desired file format.</param> /// <param name="format">The format of the file.</param> /// <returns>An array of images captured.</returns> public virtual Bitmap[] Capture( CaptureType typeOfCapture, String filename, ImageFormatHandler.ImageFormatTypes format ) { Capture( typeOfCapture ); Save( filename, format ); return images; }
/// <summary> /// Execute the capturing of window specified by it's windows handle. /// </summary> /// <param name="handle">The handle of the window to capture</param> /// <param name="filename">The name of the target file. The extension in there is ignored, /// it will replaced by an extension derived from the desired file format.</param> /// <param name="format">The format of the file.</param> /// <returns>The image which has been captured.</returns> public virtual Bitmap Capture( IntPtr handle, String filename, ImageFormatHandler.ImageFormatTypes format ) { Capture( handle ); Save( filename, format ); return images[0]; }
/// <summary> /// Capture a specific form and save it into a file. /// </summary> /// <param name="window">This is the desired window which should be captured.</param> /// <param name="filename">The name of the target file. The extension in there is ignored, /// it will replaced by an extension derived from the desired file format.</param> /// <param name="format">The format of the file.</param> /// <param name="onlyClient">When set to 'true' then only the client area of the form is captured, /// otherwise the complete window with title bar, frame etc. is captured.</param> /// <returns>The image which has been captured.</returns> public virtual Bitmap Capture( Form window, String filename, ImageFormatHandler.ImageFormatTypes format, bool onlyClient ) { Capture( window, onlyClient ); Save( filename, format ); return images[0]; }
/// <summary> /// Capture a specific form and save it into a file. /// </summary> /// <param name="window">This is the desired window which should be captured.</param> /// <param name="filename">The name of the target file. The extension in there is ignored, /// it will replaced by an extension derived from the desired file format.</param> /// <param name="format">The format of the file.</param> /// <returns>The image which has been captured.</returns> public virtual Bitmap Capture( Form window, String filename, ImageFormatHandler.ImageFormatTypes format ) { return Capture( window, filename, format, false ); }