嘿,我有一个使用silverlight API的Windows Phone 8.1应用程序。 我正从blob存储中下载此图像。
图片来自以下链接:https://[service].blob.core.windows.net/[imagename].png,只需使用URI即可在多个浏览器中展示和下载图片。
我现在想把它用作基于blobstorage的imageuri的画笔:
myOnlineImage
imagebrush
未正确创建,至少我无法将图像转换为writeablebitmapimage(从转换中获取null异常),此外,图像刷是空的,即null。但据我所知,这是方法吗?
基本
如何根据https网站的网址创建public LoadResult load(URL url) {
new Thread(() -> {
Platform.runLater(() ->{
done = false;
engine.load("");
});
attesa();
}).start();
new Thread(() -> {
Platform.runLater(() ->{
done = false;
engine.load(url.toString());
});
attesa();
}).start();
return new LoadResult(url, parsed, ex);
}
private void attesa(){
while (!done){
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
?
答案 0 :(得分:4)
我最终自己解决了这个问题:
请务必添加using 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);
此代码适用于imagebrush和writeablebitmap
答案 1 :(得分:3)
要从图像创建位图,您必须在设置URL之前开始初始化位图对象。
BitmapImage myOnlineImage = new BitmapImage();
myOnlineImage.BeginInit();
myOnlineImage.UriSource = new Uri(uploadImage.ImageUri, UriKind.RelativeOrAbsolute);
myOnlineImage.EndInit();
var imageBrush = new ImageBrush
{
ImageSource = myOnlineImage,
Stretch = Stretch.None
};
var source = FindChildShieldCanvas(CanvasImage, imageBrush);
WriteableBitmap wbm = new WriteableBitmap((BitmapImage)myOnlineImage);
ImageOnlineTest.Source = wbm;
答案 2 :(得分:1)
您可以通过以下方式使用C#执行此操作,将相应的代码替换为您的字段。
Rectangle rectangle = new Rectangle();
rectangle.StrokeThickness = 10;
rectangle.Height = 200;
rectangle.Width = 100;
rectangle.SetValue(Canvas.LeftProperty, 100d);
rectangle.SetValue(Canvas.TopProperty, 100d);
rectangle.Fill = new ImageBrush(new BitmapImage(new Uri(@"C:\User\xiaorui.dong\Pictures\profile.jpeg")));