From cca5f0fe8a9a178b8fb1335136ed5dddbdc3e29b Mon Sep 17 00:00:00 2001 From: Oskar Eichler <62393985+OskarEichler@users.noreply.github.com> Date: Fri, 28 Aug 2026 03:39:41 +0300 Subject: [PATCH] fix(windows): read complete capture streams and box JPEG quality correctly --- .prettierignore | 4 ++++ windows/RNViewShot/ViewShot.cs | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.prettierignore b/.prettierignore index 8c42668b..3479e8ba 100644 --- a/.prettierignore +++ b/.prettierignore @@ -11,6 +11,10 @@ ios/build/ example/android/build/ example/ios/build/ **/build/ +windows/**/bin/ +windows/**/obj/ +example-windows/windows/**/bin/ +example-windows/windows/**/obj/ **/.gradle/ **/.cxx/ diff --git a/windows/RNViewShot/ViewShot.cs b/windows/RNViewShot/ViewShot.cs index b93f7c28..1781aeef 100644 --- a/windows/RNViewShot/ViewShot.cs +++ b/windows/RNViewShot/ViewShot.cs @@ -39,7 +39,19 @@ public static async Task Execute(FrameworkElement view, string extension throw new InvalidOperationException("Capture is too large to base64-encode (" + ras.Size + " bytes)"); } var imageBytes = new byte[(int)ras.Size]; - await ras.AsStream().ReadAsync(imageBytes, 0, imageBytes.Length); + using (var input = ras.GetInputStreamAt(0).AsStreamForRead()) + { + var offset = 0; + while (offset < imageBytes.Length) + { + var read = await input.ReadAsync(imageBytes, offset, imageBytes.Length - offset); + if (read == 0) + { + throw new EndOfStreamException("Capture stream ended before all image bytes were read"); + } + offset += read; + } + } var data = Convert.ToBase64String(imageBytes); if (result == "data-uri") { @@ -77,7 +89,7 @@ private static async Task CaptureView(FrameworkElement view, IRandomAccessStream { var propertySet = new BitmapPropertySet { - { "ImageQuality", new BitmapTypedValue(quality, Windows.Foundation.PropertyType.Single) }, + { "ImageQuality", new BitmapTypedValue((float)quality, Windows.Foundation.PropertyType.Single) }, }; encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream, propertySet); }