Ejemplo n.º 1
0
        internal Task TakeAndSaveScreenshot()
        {
            var task = new Task(() =>
            {
                EnsureScreenshotsDirectoryExists();

                MyLog.Write("Action: TakeAndSaveScreenshot()");
                try
                {
                    var pageUrl        = new Uri(WebSpyBrowser.GetDriver().Url);
                    var host           = pageUrl.Host;
                    string newFileName = DateTime.Now.ToString("yyyy-dd-M__HH-mm-ss") + "_" + host + ".png";
                    string newFilePath = Path.Combine(ScreenshotsLocation, newFileName);

                    Screenshot screenshot = WebSpyBrowser.TakeScreenshot();
                    screenshot.SaveAsFile(newFilePath, ImageFormat.Png);
                }
                catch (Exception ex)
                {
                    MyLog.Write("Action: TakeAndSaveScreenshot() FAILED");
                    MyLog.Exception(ex);
                    throw;
                }
            });

            task.Start();
            return(task);
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var screenshot = WebSpyBrowser.TakeScreenshot();

            //screenshot.AsByteArray

            imgBox.Zoom = 100;

            using (var ms = new MemoryStream(screenshot.AsByteArray))
            {
                imgBox.Image = Image.FromStream(ms);
            }
        }