UWP - ImageBrush 到 ImageSource 的完整路径 [英] UWP - ImageBrush full path to ImageSource

查看:24
本文介绍了UWP - ImageBrush 到 ImageSource 的完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个椭圆,我想用图像填充它.我想将图像的完整路径设置为 ImageBrushImageSource 属性.但我没能完成它.

I have an ellipse and I want to fill it with image. And I would like to set full path to the image to ImageSource property of ImageBrush. But I wasn't able to accomplish it.

我尝试添加:

  • C:/Users/someuser/Pictures/untitled.png

C:\\Users\\someuser\\Pictures\\untitled.png 来自 FilePicker

C:\Users\misko\Pictures\untitled.png.

但这些都不起作用.你能向我解释一下如何正确设置完整路径吗?

But non of this works. Can you please explain to me how to properly set full path?

推荐答案

您必须先使用 FilePicker

if (file != null)
{
    var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

    var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
    await bitmapImage.SetSourceAsync(stream);

    var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);

    grid.Background = new ImageBrush
    {

        ImageSource = bitmapImage
    };
}

这篇关于UWP - ImageBrush 到 ImageSource 的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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