Image 从流中获取图像(WMS)

Image 从流中获取图像(WMS),image,stream,windows-phone-8.1,wms,Image,Stream,Windows Phone 8.1,Wms,我正在开发Windows Phone 8.1应用程序。我正在尝试从Web地图服务获取图像,并将其显示在地图控件中。我已经通过http请求获得了流,现在我想在图像中转换它 我怎么做这个部分?这就是我所拥有的: 下载流: 现在我从请求中得到了正确的流,它是一个png图像。现在我想在图像中对其进行变换。我已经尝试过使用FromStream方法,但是wp8.1似乎不支持它 你能帮我完成最后一部分吗?你可以试试这样的 HttpClient httpClient = new HttpClient(); Ht

我正在开发Windows Phone 8.1应用程序。我正在尝试从Web地图服务获取图像,并将其显示在地图控件中。我已经通过http请求获得了流,现在我想在图像中转换它

我怎么做这个部分?这就是我所拥有的:

下载流:

现在我从请求中得到了正确的流,它是一个png图像。现在我想在图像中对其进行变换。我已经尝试过使用FromStream方法,但是wp8.1似乎不支持它


你能帮我完成最后一部分吗?

你可以试试这样的

HttpClient httpClient = new HttpClient();
HttpResponseMessage request = await httpClient.GetAsync("URL").ConfigureAwait(false);

using (Stream stream = await request.Content.ReadAsStreamAsync().ConfigureAwait(false))
{
    MemoryStream memStream = new MemoryStream();
    await stream.CopyToAsync(memStream);
    memStream.Position = 0;

    CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            BitmapImage bitmap = new BitmapImage();

            bitmap.SetSource(memStream.AsRandomAccessStream());
            img.Source = bitmap;

            memStream.Dispose();
        }
    );
}
其中img是在XAML中定义的图像对象

顺便说一句,一个简单的例子

<Image Source="URL" /> 
在XAML中,如果您只需要一个位图作为图像源,那么它也可能适合您

<Image Source="URL" />