internal async Task <Stream> PlatformOpenReadAsync(ScreenshotFormat format) { if (bytes == null) { var pixels = await bmp.GetPixelsAsync().AsTask().ConfigureAwait(false); bytes = pixels.ToArray(); } var f = format switch { ScreenshotFormat.Jpeg => BitmapEncoder.JpegEncoderId, _ => BitmapEncoder.PngEncoderId }; var ms = new InMemoryRandomAccessStream(); var encoder = await BitmapEncoder.CreateAsync(f, ms).AsTask().ConfigureAwait(false); encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)Width, (uint)Height, 96, 96, bytes); await encoder.FlushAsync().AsTask().ConfigureAwait(false); return(ms.AsStreamForRead()); } }
public void WithSeleniumReporting_WithConfiguration_ShouldReturnCorrectValue( [Modest] Actor actor, IActor iactor, SeleniumReportingConfiguration configuration, IObserver <string>[] observers, ICanNotify canNotify, ITakeScreenshotStrategy takeScreenshotStrategy, ScreenshotFormat format) { var actual = ActorExtensions.WithSeleniumReporting( actor, configuration, out var actualSeleniumReporter ); TestWithSeleniumReporting(actualSeleniumReporter, actual, actor, iactor, configuration.ScreenshotDirectory, configuration.ScreenshotNameOrFormat, observers, canNotify, takeScreenshotStrategy, format); }
public static ImageCodecInfo getImageCodec(ScreenshotFormat format) { ImageCodecInfo[] formats = ImageCodecInfo.GetImageDecoders(); String expectedMime; switch (format) { case ScreenshotFormat.BMP: expectedMime = "image/bmp"; break; case ScreenshotFormat.JPEG: expectedMime = "image/jpeg"; break; case ScreenshotFormat.TIFF: expectedMime = "image/tiff"; break; default: expectedMime = "image/png"; break; } ImageCodecInfo result = null; for (int i = 0; i < formats.Length; i++) { if (formats[i].MimeType.ToLower() == expectedMime) { result = formats[i]; break; } } return result; }
public static EncoderParameters getParameters(int jpegQuality, ScreenshotFormat format) { EncoderParameters result; switch(format) { case ScreenshotFormat.BMP: result = new EncoderParameters(1); result.Param[0] = new EncoderParameter(Encoder.ColorDepth, 24); break; case ScreenshotFormat.JPEG: result = new EncoderParameters(1); result.Param[0] = new EncoderParameter(Encoder.Quality, jpegQuality); break; case ScreenshotFormat.TIFF: result = new EncoderParameters(2); EncoderParameter parameter = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionLZW); result.Param[0] = parameter; parameter = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.LastFrame); result.Param[1] = parameter; break; default: result = new EncoderParameters(2); result.Param[0] = new EncoderParameter(Encoder.Compression,(long)EncoderValue.CompressionCCITT4); result.Param[1] = new EncoderParameter(Encoder.ColorDepth, (long)24); break; } return result; }
public static EncoderParameters getParameters(int jpegQuality, ScreenshotFormat format) { EncoderParameters result; switch (format) { case ScreenshotFormat.BMP: result = new EncoderParameters(1); result.Param[0] = new EncoderParameter(Encoder.ColorDepth, 24); break; case ScreenshotFormat.JPEG: result = new EncoderParameters(1); result.Param[0] = new EncoderParameter(Encoder.Quality, jpegQuality); break; case ScreenshotFormat.TIFF: result = new EncoderParameters(2); EncoderParameter parameter = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionLZW); result.Param[0] = parameter; parameter = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.LastFrame); result.Param[1] = parameter; break; default: result = new EncoderParameters(2); result.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionCCITT4); result.Param[1] = new EncoderParameter(Encoder.ColorDepth, (long)24); break; } return(result); }
Task PlatformCopyToAsync(Stream destination, ScreenshotFormat format, int quality) { var f = ToCompressFormat(format); bmp.Compress(f, quality, destination); return(Task.CompletedTask); }
Task <Stream> PlatformOpenReadAsync(ScreenshotFormat format, int quality) { var result = new MemoryStream(); PlatformCopyToAsync(result, format, quality); result.Position = 0; return(Task.FromResult <Stream>(result)); }
async Task <Stream> PlatformOpenReadAsync(ScreenshotFormat format, int quality) { var ms = new InMemoryRandomAccessStream(); await EncodeAsync(format, ms).ConfigureAwait(false); return(ms.AsStreamForRead()); }
/// <summary> /// Save the screeshots in the specified format /// </summary> /// <param name="screenshotFormat">The format</param> /// <returns></returns> public SeleniumReportingConfiguration WithScreenshotFormat(ScreenshotFormat screenshotFormat) { return(new SeleniumReportingConfiguration(ScreenshotDirectory, ScreenshotNameOrFormat, _canNotify, TextOutputObservers, TakeScreenshotStrategy, screenshotFormat)); }
public void Equals_WithDifferentFormat_ReturnsFalse(ScreenshotFormat sut) { if (sut.Format == ScreenshotImageFormat.Bmp) { return; } Assert.False(((object)ScreenshotFormat.Bmp).Equals(sut)); }
public void GetHashCode_WithDifferentFormat_ReturnDifferentValue(ScreenshotFormat sut) { if (sut.Format == ScreenshotImageFormat.Bmp) { return; } Assert.NotEqual(ScreenshotFormat.Bmp.GetHashCode(), sut.GetHashCode()); }
async Task EncodeAsync(ScreenshotFormat format, IRandomAccessStream ms) { var f = ToBitmapEncoder(format); var encoder = await BitmapEncoder.CreateAsync(f, ms).AsTask().ConfigureAwait(false); encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)Width, (uint)Height, 96, 96, bytes); await encoder.FlushAsync().AsTask().ConfigureAwait(false); }
public async Task <byte[]> TakeScreenshotAsync(ScreenshotFormat format, ScreenshotOptions options, Viewport viewport) { var response = await _session.SendAsync(new PageScreenshotRequest { MimeType = format == ScreenshotFormat.Jpeg ? ScreenshotMimeType.ImageJpeg : ScreenshotMimeType.ImagePng, FullPage = options.FullPage, Clip = options.Clip, }).ConfigureAwait(false); return(Convert.FromBase64String(response.Data)); }
internal Task <Stream> PlatformOpenReadAsync(ScreenshotFormat format) { var data = format switch { ScreenshotFormat.Jpeg => uiImage.AsJPEG(), _ => uiImage.AsPNG() }; return(Task.FromResult(data.AsStream())); } }
public void WithScreenshotMethods_ShouldSetTheCorrectFormat(ScreenshotFormat format, MethodInfo method) { // arrange var fixture = new Fixture().Customize(new AutoMoqCustomization()); var configuration = fixture.Create <SeleniumReportingConfiguration>(); // act var actual = (SeleniumReportingConfiguration)method.Invoke(null, new object[] { configuration }); // assert Assert.Equal(format, actual.ScreenshotFormat); }
internal Task <Stream> PlatformOpenReadAsync(ScreenshotFormat format) { var f = format switch { ScreenshotFormat.Jpeg => Bitmap.CompressFormat.Jpeg, _ => Bitmap.CompressFormat.Png, }; var result = new MemoryStream(bmp.AsImageBytes(f, 100)) as Stream; return(Task.FromResult(result)); }
public async Task <byte[]> TakeScreenshotAsync(ScreenshotFormat format, ScreenshotOptions options, Viewport viewport) { await Client.SendAsync(new PageBringToFrontRequest()).ConfigureAwait(false); var clip = options.Clip?.ToViewportProtocol(); var result = await Client.SendAsync(new PageCaptureScreenshotRequest { Format = format.ToStringFormat(), Quality = options.Quality, Clip = clip, }).ConfigureAwait(false); return(result.Data); }
public async Task RendersAsImage(ScreenshotFormat type) { var view = new TStub() { Height = 100, Width = 100, }; var result = await GetValueAsync(view, handler => handler.VirtualView.CaptureAsync()); Assert.NotNull(result); using var stream = await result.OpenReadAsync(type); Assert.True(stream.Length > 0); }
internal async Task <Stream> PlatformOpenReadAsync(ScreenshotFormat format) { var stream = new MemoryStream(); var f = format switch { ScreenshotFormat.Jpeg => Bitmap.CompressFormat.Jpeg, _ => Bitmap.CompressFormat.Png, }; await bmp.CompressAsync(f, 100, stream).ConfigureAwait(false); stream.Position = 0; return(stream); }
internal Task <Stream> PlatformOpenReadAsync(ScreenshotFormat format) { var content = format switch { ScreenshotFormat.Jpeg => ImageCodecInfo.GetImageEncoders().FirstOrDefault(x => x.FormatDescription == "JPEG") ?? throw new InvalidOperationException("No JPEG encoder found"), ScreenshotFormat.Png => ImageCodecInfo.GetImageEncoders().FirstOrDefault(x => x.FormatDescription == "PNG") ?? throw new InvalidOperationException("No PNG encoder found"), _ => throw new NotImplementedException() }; var encoderParameters = new EncoderParameters(); encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 50L); var stream = new MemoryStream(); bmp.Save(stream, content, encoderParameters); return(Task.FromResult <Stream>(stream)); } }
private async Task <byte[]> ScreenshotAsync(ScreenshotFormat format, ScreenshotOptions options, Viewport viewport) { bool shouldSetDefaultBackground = options.OmitBackground && format == ScreenshotFormat.Png; if (shouldSetDefaultBackground) { await _page.Delegate.SetBackgroundColorAsync(Color.FromArgb(0, 0, 0, 0)).ConfigureAwait(false); } byte[] result = await _page.Delegate.TakeScreenshotAsync(format, options, viewport).ConfigureAwait(false); if (shouldSetDefaultBackground) { await _page.Delegate.SetBackgroundColorAsync().ConfigureAwait(false); } return(result); }
private SeleniumReportingConfiguration(string screenshotDirectory, string screenshotNameOrFormat, ICanNotify canNotify, ImmutableArray <IObserver <string> > textOutputObservers, ITakeScreenshotStrategy takeScreenshotStrategy, ScreenshotFormat screenshotFormat) { if (string.IsNullOrEmpty(screenshotDirectory)) { throw new ArgumentNullException(nameof(screenshotDirectory)); } if (string.IsNullOrEmpty(screenshotNameOrFormat)) { throw new ArgumentNullException(nameof(screenshotNameOrFormat)); } ScreenshotDirectory = screenshotDirectory; ScreenshotNameOrFormat = screenshotNameOrFormat; _canNotify = canNotify; TextOutputObservers = textOutputObservers; TakeScreenshotStrategy = takeScreenshotStrategy; ScreenshotFormat = screenshotFormat ?? throw new ArgumentNullException(nameof(screenshotFormat)); }
public static ImageCodecInfo getImageCodec(ScreenshotFormat format) { ImageCodecInfo[] formats = ImageCodecInfo.GetImageDecoders(); string expectedMime; switch (format) { case ScreenshotFormat.BMP: expectedMime = "image/bmp"; break; case ScreenshotFormat.JPEG: expectedMime = "image/jpeg"; break; case ScreenshotFormat.TIFF: expectedMime = "image/tiff"; break; default: expectedMime = "image/png"; break; } ImageCodecInfo result = null; for (int i = 0; i < formats.Length; i++) { if (formats[i].MimeType.ToLower() == expectedMime) { result = formats[i]; break; } } return(result); }
Task PlatformCopyToAsync(Stream destination, ScreenshotFormat format, int quality) => throw ExceptionUtils.NotSupportedOrImplementedException;
public Screenshot(ScreenshotFormat format, int width, int height, in Intrinsic intrinsic, in Pose cameraPose,
private void ShotGetFormat(out ScreenshotFormat format) { String ext; ShotGetFormat(out format, out ext); }
private void ShotGetFormat(out ScreenshotFormat format, out String extension) { switch (ImgFormat.SelectedIndex) { case 1: format = ScreenshotFormat.BMP; extension = ".bmp"; break; case 2: format = ScreenshotFormat.JPEG; extension = ".jpg"; SettingsFile.SetValue("Screenshots", "JPEGQuality", JPGQual.Value); break; case 3: format = ScreenshotFormat.TIFF; extension = ".tif"; break; default: format = ScreenshotFormat.PNG; extension = ".png"; break; } }
internal Task <Stream> PlatformOpenReadAsync(ScreenshotFormat format) => throw ExceptionUtils.NotSupportedOrImplementedException;
static Bitmap.CompressFormat ToCompressFormat(ScreenshotFormat format) => format switch {
public Task <Stream> OpenReadAsync(ScreenshotFormat format = ScreenshotFormat.Png) => PlatformOpenReadAsync(format);
public Task CopyToAsync(Stream destination, ScreenshotFormat format = ScreenshotFormat.Png, int quality = 100) => PlatformCopyToAsync(destination, format, quality);
public Task <Stream> OpenReadAsync(ScreenshotFormat format = ScreenshotFormat.Png, int quality = 100) => PlatformOpenReadAsync(format, quality);
private async Task <byte[]> PerformScreenshot(ScreenshotFormat format, ScreenshotOptions options) { Viewport overridenViewport = null; var viewport = _page.Viewport; Viewport viewportSize = null; if (viewport == null) { viewportSize = await _page.EvaluateAsync <Viewport>(@"() => { if (!document.body || !document.documentElement) return; return { width: Math.max(document.body.offsetWidth, document.documentElement.offsetWidth), height: Math.max(document.body.offsetHeight, document.documentElement.offsetHeight), }; }").ConfigureAwait(false); if (viewportSize == null) { throw new PlaywrightSharpException(ScreenshotDuringNavigationError); } } if (options.FullPage && !_page.Delegate.CanScreenshotOutsideViewport()) { var fullPageRect = await _page.EvaluateAsync <Size>(@"() => { if (!document.body || !document.documentElement) return null; return { width: Math.max( document.body.scrollWidth, document.documentElement.scrollWidth, document.body.offsetWidth, document.documentElement.offsetWidth, document.body.clientWidth, document.documentElement.clientWidth ), height: Math.max( document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight ), }; }").ConfigureAwait(false); if (fullPageRect == null) { throw new PlaywrightSharpException(ScreenshotDuringNavigationError); } overridenViewport = viewport != null?viewport.Clone() : new Viewport(); overridenViewport.Height = fullPageRect.Height; overridenViewport.Width = fullPageRect.Width; await _page.SetViewportAsync(overridenViewport).ConfigureAwait(false); } else if (options.Clip != null) { options.Clip = TrimClipToViewport(viewport, options.Clip); } byte[] result = await ScreenshotAsync(format, options, overridenViewport ?? viewport).ConfigureAwait(false); if (overridenViewport != null) { if (viewport != null) { await _page.SetViewportAsync(viewport).ConfigureAwait(false); } else { await _page.Delegate.ResetViewportAsync(viewportSize).ConfigureAwait(false); } } return(result); }
private async Task <byte[]> PerformScreenshotElementAsync(ElementHandle handle, ScreenshotFormat format, ScreenshotOptions options) { Viewport overridenViewport = null; Viewport viewportSize = null; var maybeBoundingBox = await _page.Delegate.GetBoundingBoxForScreenshotAsync(handle).ConfigureAwait(false); if (maybeBoundingBox == null) { throw new PlaywrightSharpException("Node is either not visible or not an HTMLElement"); } var boundingBox = maybeBoundingBox; if (boundingBox.Width == 0) { throw new PlaywrightSharpException("Node has 0 width."); } if (boundingBox.Height == 0) { throw new PlaywrightSharpException("Node has 0 height."); } boundingBox = EnclosingIntRect(boundingBox); var viewport = _page.Viewport; if (!_page.Delegate.CanScreenshotOutsideViewport()) { if (viewport == null) { var maybeViewportSize = await _page.EvaluateAsync <Viewport>(@"() => { if (!document.body || !document.documentElement) return; return { width: Math.max(document.body.offsetWidth, document.documentElement.offsetWidth), height: Math.max(document.body.offsetHeight, document.documentElement.offsetHeight), }; }").ConfigureAwait(false); if (maybeViewportSize == null) { throw new PlaywrightSharpException(ScreenshotDuringNavigationError); } viewportSize = maybeViewportSize; } else { viewportSize = viewport; } if (boundingBox.Width > viewportSize.Width || boundingBox.Height > viewportSize.Height) { overridenViewport = (viewport ?? viewportSize).Clone(); overridenViewport.Width = Convert.ToInt32(Math.Max(viewportSize.Width, boundingBox.Width)); overridenViewport.Height = Convert.ToInt32(Math.Max(viewportSize.Height, boundingBox.Height)); await _page.SetViewportAsync(overridenViewport).ConfigureAwait(false); } await handle.ScrollIntoViewIfNeededAsync().ConfigureAwait(false); maybeBoundingBox = await _page.Delegate.GetBoundingBoxForScreenshotAsync(handle).ConfigureAwait(false); if (maybeBoundingBox == null) { throw new PlaywrightSharpException("Node is either not visible or not an HTMLElement"); } boundingBox = EnclosingIntRect(maybeBoundingBox !); } if (overridenViewport == null) { options.Clip = boundingBox; } byte[] result = await ScreenshotAsync(format, options, overridenViewport ?? viewport).ConfigureAwait(false); if (overridenViewport != null) { if (viewport != null) { await _page.SetViewportAsync(viewport).ConfigureAwait(false); } else { await _page.Delegate.ResetViewportAsync(viewportSize).ConfigureAwait(false); } } return(result); }