• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

以编程方式更改图像源

用户头像
it1352
帮助1

问题说明

我无法弄清楚如何将磁盘上的图像动态加载到Xaml图像控件.

I cannot figure out how to dynamically load an image from the disk to a Xaml image control.

<Image x:Name="imgLogo" ....../>

然后在我的c 类中,我找不到我发现的任何示例.大多数都在c#中.令人烦恼的是,我一直看到使用System.Windows.Media::ImageSource,但这不在我的框架中.

Then in my c class, i cannot get any examples working that I have found. Most are in c#. One annoyance is that I keep seeing System.Windows.Media::ImageSource used, but that is not in my framework.

有人可以给我举个例子吗?我来自iOS世界,不习惯MS及其框架.

Can someone please show me an example. I'm coming from the iOS world and am not used to MS and their frameworks.

谢谢

正确答案

#1

尝试一下,它在C#中,但是转换起来应该很容易:

Try this, it's in C# but should be fairly easy to convert:

using Windows.UI.Xaml.Media.Imaging;

<Image Margin="5" Source="{Binding BMImage}"  />


bmImage = new BitmapImage();
bmImage.UriSource = new Uri(new Uri(
     *your file path*, 
     *your image name*);


BitmapImage bmImage;
public BitmapImage BMImage
{
    get
    {
        return bmImage;
    }
}

来自此处(我的博客).

要更改图像,只需更改bmImage的值并调用NotifyPropertyChanged(()=>BMImage);(假设您已进行设置)

To change the image, just change the value of bmImage and call NotifyPropertyChanged(()=>BMImage); (assuming you have that setup)

请参见此处有关Microsoft如何使用图像的示例.

See here for Microsoft's example of how to use images.

请参见此处 Windows.UI.Xaml.Media.Imaging名称空间.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcjjche
系列文章
更多 icon
同类精品
更多 icon
继续加载