Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when using RenderTargetBitmap(UWP/C#) #72

Open
DmitryBorodiy opened this issue Sep 11, 2022 · 2 comments
Open

Exception when using RenderTargetBitmap(UWP/C#) #72

DmitryBorodiy opened this issue Sep 11, 2022 · 2 comments

Comments

@DmitryBorodiy
Copy link

DmitryBorodiy commented Sep 11, 2022

An exception occurs when I try to take a snapshot of the MonacoEditor UI element.

                RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
                await renderTargetBitmap.RenderAsync(Editor);
                var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();

                StorageFile image = await ApplicationData.Current.LocalFolder.CreateFileAsync("image.png", 
                CreationCollisionOption.ReplaceExisting);

                using (var stream = await image.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);

                    encoder.SetPixelData(
                        BitmapPixelFormat.Bgra8,
                        BitmapAlphaMode.Ignore,
                        (uint)renderTargetBitmap.PixelWidth,
                        (uint)renderTargetBitmap.PixelHeight,
                        DisplayInformation.GetForCurrentView().LogicalDpi,
                        DisplayInformation.GetForCurrentView().LogicalDpi,
                        pixelBuffer.ToArray());

                    await encoder.FlushAsync();

                    await stream.FlushAsync();
                    stream.Dispose();

                    BitmapImage bitmap = new BitmapImage();
                    bitmap.SetSource(await image.OpenAsync(FileAccessMode.Read));
               }

Value does not fall within the expected range.System.Private.CoreLib
Exception thrown: 'System.ArgumentException' in System.Private.CoreLib.dll

@DmitryBorodiy
Copy link
Author

This stopped working after upgrading to beta 0.9.0. I rolled back to 0.8.1.

@hawkerm
Copy link
Owner

hawkerm commented Oct 8, 2022

@DmitryBorodiy can you provide more info in the stack trace? Can you turn on native debugging and get more of the native stack from the platform? ArgumentException isn't that helpful here. The control is just a WebView, so I don't really know what would be going on here or what would have changed between versions except maybe offloading the WebView thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants