我有一个存储为IRandomAccessStreamReference的图像,我需要将其用作Ellipse中的填充。我该如何使用它?
...
static IRandomAccessStreamReference myThumbnail;
...
var contactStore = await ContactManager.RequestStoreAsync();
var contact = await contactStore.GetMeContactAsync();
myThumbnail = contact.Thumbnail;
...
Ellipse ellipse = new Ellipse
{
Height = 32,
Width = 32,
Fill = myThumbnail, // How do I use this?
};
答案 0 :(得分:0)
因此,您需要使用ImageBrush
类,该类派生自基类Brush
类。
该类包含ImageSource
属性,BitmapImage
的基类。另外,例如BitmapImage
类,我建议使用DecodePixelWidth
或DecodePixelHeight
属性。
var thumbailImageBrush = new ImageBrush();
using (var randomStream = await myThumbnail.OpenReadAsync())
{
var bitmapImage = new BitmapImage();
bitmapImage.DecodePixelWidth = 32; // just good practice
await bitmapImage.SetSourceAsync(randomStream);
thumbailImageBrush.ImageSource = bitmapImage;
}
var ellipse = new Ellipse
{
Height = 32,
Width = 32,
Fill = thumbailImageBrush
};