C# WPF Load images from the exe folder

喜你入骨 提交于 2019-11-29 15:45:35
Clemens

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.

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);
NSGaga

You could do something like this:

Source="pack://siteoforigin:,,,/Images/someimage.png"  

and use images off of your bin/app folder. Take a look at this link for more info...

Custom graphic in WPF application?

What is application's site of origin and when to use it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!