public void ExportAsync(string html, Stream output) { using (var driver = new PhantomJSDriver()) { //string dataUri = string.Format("data:text/html;base64,{0}", // Convert.ToBase64String(new UnicodeEncoding().GetBytes(html))); string dataUri = string.Format("data:text/html;charset=utf-8,{0}", EncodeNoneAscii(html)); driver.Navigate().GoToUrl(dataUri); var screenshot = driver.TakeScreenshot(); var outBytes = screenshot.AsByteArray; output.Write(outBytes, 0, outBytes.Length); } }
public MemoryStream MakeScreenshot(string url, string hashValue, int width, int height) { try { var driver = new PhantomJSDriver(_PhantomJsOptinons.Value.PhantomJsDriverPath); driver.Manage().Window.Maximize(); driver.Navigate().GoToUrl(url); MemoryStream resultStream = new MemoryStream(driver.TakeScreenshot().AsByteArray); driver.Quit(); return(resultStream); } catch (Exception ex) { _Logger.LogError($"Error occured: ", ex); return(null); } }
public Image TakeScreenshotLarge(string url, String _testID, string userName, string userLastName, string os, bool pgR) { PhantomJSDriver _driver = new PhantomJSDriver(@"C:/WEBDRIVER"); _driver.Manage().Window.Size = new System.Drawing.Size(1920, 1080); _driver.Navigate().GoToUrl(url); Screenshot _ce = _driver.TakeScreenshot(); Image _ceImg = ScreenshotToImage(_ce); string _cheminCaptureEcran = _hndlr.PathProject() + "DESKTOPSCR\\LARGE" + userName + userLastName + os + DateTime.Now.ToString("MMdHHmmss") + _testID + ".jpg"; var encoder = ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == ImageFormat.Jpeg.Guid); var encParams = new EncoderParameters() { Param = new[] { new EncoderParameter(Encoder.Quality, 75L) } }; _ceImg.Save(_cheminCaptureEcran, encoder, encParams); return(_ceImg); }