1

I try to save the UI elements into an image file. but we have More UI elements(like 100 list of rows). So the image quality is very poor. Is there any possibility to convert the UI elements into multiple images or get the image with High Quality please share some suggestions for this.

I have tried to save the image file using the below code:

 public async Task GenereateImage(UIElement root) { RenderTargetBitmap renderTargetBitmap1 = new RenderTargetBitmap(); await renderTargetBitmap1.RenderAsync(root, (int)root.RenderSize.Width, (int)root.RenderSize.Height); var pixelBuffer1 = await renderTargetBitmap1.GetPixelsAsync(); var disply = DisplayInformation.GetForCurrentView(); var savePicker = new FileSavePicker(); savePicker.DefaultFileExtension = ".png"; savePicker.FileTypeChoices.Add(".png", new List<string> { ".png" }); savePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; savePicker.SuggestedFileName = "snapshot.png"; // Prompt the user to select a file var saveFile = await savePicker.PickSaveFileAsync(); // Verify the user selected a file if (saveFile == null) return; // Encode the image to the selected file on disk using (var fileStream = new Windows.Storage.Streams.InMemoryRandomAccessStream()) { var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream); encoder.SetPixelData( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)renderTargetBitmap1.PixelWidth, (uint)renderTargetBitmap1.PixelHeight, DisplayInformation.GetForCurrentView().LogicalDpi, DisplayInformation.GetForCurrentView().LogicalDpi, pixelBuffer1.ToArray()); await encoder.FlushAsync(); } } 

And the result image be like is:

enter image description here

6
  • Have you tried insert listview into scrollviewer then render scrollviewer to RenderTargetBitmap ? Commented Aug 7, 2020 at 9:13
  • Ya, I have tried, if I pass the scroll viewer, the first page only shown. doesn't show the full scrollable page. Also, I have tried scrollviewer.content, which gives the entire scrollable data with poor quality as per said in above. Commented Aug 7, 2020 at 10:51
  • @CoCaIceDew any other suggestions Commented Aug 7, 2020 at 14:16
  • I'm afraid there is no better way to render all content of list to bitmap image. Commented Aug 10, 2020 at 1:32
  • And have you tried use ContainerFromIndex method to get each listviewitem and render them separately? Commented Aug 10, 2020 at 1:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.