AliSafari186 AliSafari186 - 11 days ago 6
C# Question

how to change image source to address on disk in runtime wpf c#

This link answers how to change image source in run-time but it's not work with addresses from disk like below:

recivedPic.Source = new BitmapImage(new Uri(@"C:\Users\ali\Desktop\Rubik-SMS\Rubik-SMS\Rubik-SMS\Images\Back.jpg" , UriKind.Relative));

Only work with addresses like below(pictures belong to project):

recivedPic.Source = new BitmapImage(new Uri(@"Images\Back.jpg" , UriKind.Relative));

I need the first one but nothing shows, any suggestion?

mww mww

You need use BitmapImage with uri only. Absolute path isn't a relative so you cant use UriKind.Relative.

Absolute URIs are characterized by a complete reference to the resource (example:, while a relative Uri depends on a previously defined base URI (example: /index.html).

this.yourImage.Source = new BitmapImage(new Uri("c:\\img.jpg"));


img.UriSource = new Uri("d:\\img.jpg");
this.image1.Source = img;