gpt4 book ai didi

image - 从 url 创建 imagebrush、位图和 writeablebitmap

转载 作者:行者123 更新时间:2023-12-04 11:35:54 25 4
gpt4 key购买 nike

嘿,我有一个使用 silverlight API 的 Windows Phone 8.1 应用程序。我正在从我的 blob 存储中下载此图像。

Image to be downloaded

该图像来自这样的链接:https://[service].blob.core.windows.net/[imagename].png只需使用 URI,即可在多个浏览器中显示和下载图像。

我现在想将其用作基于 blobstorage 中的 imageuri 的图像画笔:

// 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(从转换中获得 null 异常),此外 imagebrush 为空,即 null。但据我所知这是这样做的方法吗?

基本上

如何根据 https 站点的 URL 创建 imagebrush

最佳答案

我最终自己解决了这个问题:

记住添加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

关于image - 从 url 创建 imagebrush、位图和 writeablebitmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33854553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com