Ejemplo n.º 1
0
        /// <summary>
        /// Do it....
        /// </summary>
        public MainForm()
        {
            InitializeComponent();
            pathName = String.Format("{0}\\Data\\", Path.GetDirectoryName(Application.ExecutablePath));
            if (! Directory.Exists(pathName))
            {
                Directory.CreateDirectory(pathName);
            }

            handlers = new ImageFormatHandler();
            capture = new ScreenCapture(handlers);
        }
Ejemplo n.º 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (form != null)
     {
         try
         {
             ImageFormatHandler handlers = new ImageFormatHandler();
             ScreenCapture capture = new ScreenCapture(handlers);
             pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
             pictureBox1.Image = capture.Capture(form, @"XunitFormsCapture\");
             CompareControlCaptureAction action = new CompareControlCaptureAction(capture.LastCapture, null);
             writer.AddAction(action);
             textBox.Text = writer.Test;
         }
         catch (ObjectDisposedException)
         {
             MessageBox.Show("Please re-open your form.");
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creator
 /// </summary>
 public ScreenCapture()
 {
     doc.PrintPage += new PrintPageEventHandler(printPage);
     formatHandler = new ImageFormatHandler();
 }
Ejemplo n.º 4
0
        /// <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;

            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, ex);
                MessageBox.Show(s, "Capture failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 5
0
 /// <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>
 /// <remarks>
 /// This call uses the <i>Win32 API</i> and should therefore not be used in your
 /// code if you don't want to depend on <i>Win32</i>. <c>internal</c> Takes care
 /// of this issue.
 /// </remarks>
 internal Bitmap Capture(IntPtr handle, string filename, ImageFormatHandler.ImageFormatTypes format)
 {
     Capture(handle);
     Save(filename, format);
     return images[0];
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
0
 /// <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];
 }
Ejemplo n.º 8
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];
 }
Ejemplo n.º 9
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)
 {
     window.Focus();
     return Capture(window, filename, format, false);
 }
Ejemplo n.º 10
0
        /// <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;
        }
Ejemplo n.º 11
0
        /// <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;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Creator
 /// </summary>
 public ScreenCapture()
 {
     doc.PrintPage += new PrintPageEventHandler(printPage);
     formatHandler  = new ImageFormatHandler();
 }