I am accessing an image from a blob storage on my azure service. I am returning the uri
for the image and then uses HttpClient to try and download it. The uri
is verified to be correct.
using (HttpClient client = new HttpClient())
{
try
{
HttpResponseMessage response = await client.GetAsync(new Uri(((App)Application.Current).results.statsInformation.ImageBlob.ImageUri, UriKind.RelativeOrAbsolute));
if (response != null && response.StatusCode == HttpStatusCode.OK)
{
using (var stream = await response.Content.ReadAsStreamAsync())
{
using (var memStream = new MemoryStream())
{
await stream.CopyToAsync(memStream);
memStream.Position = 0;
memStream.Seek(0, SeekOrigin.Begin);
myOnlineImage.SetSource(memStream.AsRandomAccessStream());
}
}
}
}
catch (Exception)
{
throw;
}
}
The image from the server is stored in the variable myOnlineImage
. I then want to extract the pixel information using myOnlineImage.PixelBuffer.ToArray();
. Is this because the image has not been downloaded correctly? Can anyone help me with options to solve this?
The exception that I am receiving is:
Exception
Message "Value cannot be null.\r\nParameter name: source"
StackTrace " at System.Runtime.InteropServices.Marshal.CopyToManaged(IntPtr source, Object destination, Int32 startIndex, Int32 length)\r\n at System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.CopyTo(IBuffer source, UInt32 sourceIndex, Byte[] destination, Int32 destinationIndex, Int32 count)\r\n at System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.ToArray(IBuffer source, UInt32 sourceIndex, Int32 count)\r\n at System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.ToArray(IBuffer source)\r\n at Stonegaard_endless_runner.MainPage.d__7.MoveNext()"
Extra
I have checked that I have thread access to the image.