I'm trying to create a bitmap image, and have the following code:
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(uielement);
IBuffer pixels = await renderTargetBitmap.GetPixelsAsync();
. . .
var pixelArray = pixels.ToArray();
In order to get a ToArray()
extension, I came across this question. So I added:
using System.Runtime.InteropServices.WindowsRuntime; // For ToArray
To my code. However, when I run, I get the following error:
Exception thrown: 'System.ArgumentException' in System.Runtime.WindowsRuntime.dll
Additional information: The specified buffer index is not within the buffer capacity.
When I drill into the details, it says in the Stack Trace:
at >System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.ToArray(IBuffer source, UInt32 sourceIndex, Int32 count) at >System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.ToArray(IBuffer source)
Is this method of extracting a pixel array still applicable to the UWP? If it is, is there any way to get more detail from this error message?