WPF图像加载问题 [英] WPF image load problem

查看:105
本文介绍了WPF图像加载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我正在使用WPF,我想将图像加载到主窗口中的图像控件中.请帮我解决一下..当我运行该应用程序时,图像应该加载到它上..

hello every one

i am working with WPF and i want to load an image in a image controll on my main window plaese help me out on this.. when i run the application the image should load to it..

推荐答案

You may just add the images as resources to your Visual Studio project. Then they will be packed into the assembly of the executable and you don't need to copy them separately.

Create a folder in your project (let's say called Images) and add your images to that folder.


确保将图像的生成操作"设置为资源".

现在,您可以通过适当的Pack URI简单地从此类资源创建BitmapImage:


Make sure that the Build Action for the images is set to Resource.

Now you can simply create a BitmapImage from such a resource by an appropriate Pack URI:

var uri = new Uri("pack://application:,,,/Images/SomeImage.png");
image.Source = new BitmapImage(uri);


这篇关于WPF图像加载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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