We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

ArgumentException on RenderAsync

Thread ID:

Created:

Updated:

Platform:

Replies:

128227 Jan 9,2017 05:58 PM UTC Jan 10,2017 09:28 AM UTC UWP 1
loading
Tags: SfDiagram
Pierre-Christophe DUS
Asked On January 9, 2017 05:58 PM UTC

Hello,

I use SfDiagram to add some shapes on pictures taken by the users through the camera.

But for exporting the result, I use the method given by Martin Kurek there: 
Export uwp diagram to image

The method GenerateImage() looks like this:
protected async Task<IRandomAccessStream> GenerateImage(UIElement diagram)
{           
	// Render to an image at the current system scale and retrieve pixel contents
	var renderTargetBitmap = new RenderTargetBitmap();

	// unselect all nodes
	ObservableCollection<TraNode> nodes = ((diagram as SfDiagram).Nodes as ObservableCollection<TraNode>);
	if(nodes != null && nodes.Count > 0)
	{
		foreach (var node in nodes)
		{
			node.IsSelected = false;
		}
	}

	await renderTargetBitmap.RenderAsync(diagram);
	var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();

	var pixelBytes = new byte[pixelBuffer.Length];
	using (var reader = DataReader.FromBuffer(pixelBuffer))
	{
		reader.ReadBytes(pixelBytes);
	}
			   
	IRandomAccessStream stream = new InMemoryRandomAccessStream();
	var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);

	encoder.SetPixelData(
		BitmapPixelFormat.Bgra8,
		BitmapAlphaMode.Straight,
		(uint)renderTargetBitmap.PixelWidth,
		(uint)renderTargetBitmap.PixelHeight,
		DisplayInformation.GetForCurrentView().LogicalDpi,
		DisplayInformation.GetForCurrentView().LogicalDpi,
		pixelBytes);

	await encoder.FlushAsync();
   
	return stream;
}

But I encounter an exception in some cases, when I use this method for the second time:
- product page: the user clicks on "Add" to add a first photo => OK
- camera page: the user takes a photo with the camera => OK
- diagram's page: the user edit the photo by adding shapes => OK
diagram's page: the user exports the image => OK
- product page: the first image has been added => OK
- product page: the user clicks on "Add" to add a second photo => OK
- camera page: the user takes a photo with the camera => OK
- diagram's page: the user edit the photo by adding shapes => OK
diagram's page: the user exports the image => exception

The exception occurs on "RenderTargetBitmap.RenderAsync" :
Exception
Details

Would you have any idea?
Could it be a problem of Dispose when the user leaves the diagram's page for the first time?

Regards,

Keerthivasan Ramamoorthy [Syncfusion]
Replied On January 10, 2017 09:28 AM UTC

Hi Pierre,  
Reported issue:” The Value does not fall within the expected range”. 
 
We have analyzed your reported issue. The RenderTargetBitmap can't render something which is not in the visual tree, or in popup, etc. Please refer the msdn link for the details from “XAML visuals and RenderTargetBitmap capture capabilities” title
 
  
Regards,  
Keerthivasan R.  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;