以编程方式更改图像源 [英] change image source programmatically
问题描述
我无法弄清楚如何将磁盘上的图像动态加载到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.
谢谢
推荐答案
尝试一下,它在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}" Height="100"/>
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
名称空间.
这篇关于以编程方式更改图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!