【发布时间】:2016-10-02 13:43:13
【问题描述】:
我正在访问我的 azure 服务上的 blob 存储中的图像。我正在返回图像的uri,然后使用 HttpClient 尝试下载它。 uri 已验证正确。
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;
}
}
来自服务器的图像存储在变量myOnlineImage 中。然后我想使用myOnlineImage.PixelBuffer.ToArray(); 提取像素信息。这是因为图像没有正确下载吗?谁能帮我解决这个问题?
我收到的例外是:
例外
消息“值不能为空。\r\n参数名称:源”
StackTrace " 在 System.Runtime.InteropServices.Marshal.CopyToManaged(IntPtr source, Object destination, Int32 startIndex, Int32 length)\r\n 在 System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.CopyTo(IBuffer source, UInt32 sourceIndex , Byte[] destination, Int32 destinationIndex, Int32 count)\r\n 在 System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.ToArray(IBuffer source, UInt32 sourceIndex, Int32 count)\r\n 在 System.Runtime.InteropServices.WindowsRuntime .WindowsRuntimeBufferExtensions.ToArray(IBuffer source)\r\n at Stonegaard_endless_runner.MainPage.d__7.MoveNext()"
额外
我已检查我是否有线程访问图像。
【问题讨论】:
标签: c# uwp writeablebitmap