Rebeca Rdi
Rebeca Rdi

Reputation: 55

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

Upvotes: 4

Views: 9049

Answers (2)

Clemens
Clemens

Reputation: 128013

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

Upvotes: 6

NSGaga
NSGaga

Reputation: 14302

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

Upvotes: 2

Related Questions