Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WPF Load images from the exe folder

i want to move my program from a pc to another but the problem is the images are not loaded on any other pc (Source problem) . So i was wondering if i could just create a folder where the exe is placed and name it Resources and to load every image from there.

image2.Source = new BitmapImage(new Uri(@"Res\startoh.png"));
like image 991
Rebeca Rdi Avatar asked Oct 28 '25 04:10

Rebeca Rdi


1 Answers

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.

enter image description here

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

enter image description here

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);
like image 197
Clemens Avatar answered Oct 29 '25 18:10

Clemens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!