从URL创建的ImageBrush,位图和WriteableBitmap的 [英] Create imagebrush, bitmap and writeablebitmap from an url

查看:165
本文介绍了从URL创建的ImageBrush,位图和WriteableBitmap的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我在使用Silverlight的API一款Windows Phone 8.1的应用程序。
我从我的Blob存储下载此图片。

Hey I have a windows phone 8.1 app using the silverlight API. I am downloading this image from my blob storage.

图片是从这样一个链接来:<一href=\"https://[service].blob.core.windows.net/[imagename].png\">https://[service].blob.core.windows.net/[imagename].png并且图像可以showned并在多个浏览器下载的,只使用URI。

The image is coming from a link like this: https://[service].blob.core.windows.net/[imagename].png and the image can be showned and downloaded in multiple browsers, just using the URI.

我现在想用这个作为基于来自blobstorage的imageuri一个的ImageBrush:

I now want to use this as a imagebrush based on the imageuri from the blobstorage:

// If we have a returned SAS.
                BitmapImage myOnlineImage = new BitmapImage();
                myOnlineImage.UriSource = new Uri(uploadImage.ImageUri, UriKind.RelativeOrAbsolute);
                //ImageOnlineTest.Source = myOnlineImage;
                var imageBrush = new ImageBrush
                {
                    ImageSource = myOnlineImage,
                    Stretch = Stretch.None
                };
                var source = FindChildShieldCanvas(CanvasImage, imageBrush);

                WriteableBitmap wbm = new WriteableBitmap((BitmapImage)myOnlineImage);
                ImageOnlineTest.Source = wbm;

myOnlineImage 建立不正确,至少我可以将图像无法转换为writeablebitmapimage(正从转换空除外),并在另外的ImageBrush是空的,即空。但据我所知,这是做它的方式?

The myOnlineImage is not created correctly, at least I cannot convert the image to a writeablebitmapimage (getting a null exception from the conversion), and in addition the imagebrush is empty, i.e. null. But as far as I know this is the way to do it?

所以basicly

如何创建一个的ImageBrush 基于一个url到HTTPS站点?

How do I create an imagebrush based on an url to a https site?

推荐答案

我最终解决自己的问题:

I ended up solving the issue myself:

记住要添加使用System.Runtime.InteropServices.WindowsRuntime;

// If we have a returned SAS.
                BitmapImage myOnlineImage = new BitmapImage();

                //myOnlineImage.UriSource = new Uri(uploadImage.ImageUri, UriKind.RelativeOrAbsolute);
                using (var webCLient = new Windows.Web.Http.HttpClient())
                {
                    webCLient.DefaultRequestHeaders.Add("User-Agent", "bot");
                    var responseStream = await webCLient.GetBufferAsync(new Uri(uploadImage.ImageUri, UriKind.RelativeOrAbsolute));
                    var memoryStream = new MemoryStream();//responseStream.ToArrayAsStream().ReadAsync());

                    memoryStream.Write(responseStream.ToArray(), 0, responseStream.ToArray().Length);
                    memoryStream.Position = 0;
                    myOnlineImage.SetSource(memoryStream);

                }
                //ImageOnlineTest.Source = myOnlineImage;
                var imageBrush = new ImageBrush
                {
                    ImageSource = myOnlineImage,
                    Stretch = Stretch.None
                };
                var source = FindChildShieldCanvas(CanvasImage, imageBrush);

                WriteableBitmap wbm = new WriteableBitmap((BitmapImage)myOnlineImage);

这code ++工程,既为的ImageBrush和WriteableBitmap的

This code works, both for the imagebrush and writeablebitmap

这篇关于从URL创建的ImageBrush,位图和WriteableBitmap的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆