Ejemplo n.º 1
0
        private void CaptureScreenshot()
        {
            var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                           Screen.PrimaryScreen.Bounds.Height,
                                           PixelFormat.Format32bppArgb);

            // Create a graphics object from the bitmap.
            var gfxScreenshot = Graphics.FromImage(bmpScreenshot);

            // Take the screenshot from the upper left corner to the right bottom corner.
            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                                         Screen.PrimaryScreen.Bounds.Y,
                                         0,
                                         0,
                                         Screen.PrimaryScreen.Bounds.Size,
                                         CopyPixelOperation.SourceCopy);

            // Save the screenshot to the specified path that the user has chosen.
            string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";

            bmpScreenshot.Save(fileName, ImageFormat.Png);
            report.ReportImage("screenshot", fileName);
            File.Delete(fileName);
        }
 public void TestWithScreenshot()
 {
     report.Step("About to add screenshot to the report");
     new ScreenCapture().CaptureScreenToFile("C:\\temp2.gif", ImageFormat.Png);
     report.ReportImage("My Image", "c:\\temp2.gif");
 }