Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change image source on runtime?

I get new bitmap from some other component ( dont have any control on the other component ) every 5 seconds and i need to update my wpf image control with the new bitmap ( every 5 seconds ... ).

I cant find any way to update this wpf image control in run-time.

How can i do it ?

Thanks.

like image 537
Yanshof Avatar asked Apr 09 '26 10:04

Yanshof


2 Answers

There is a another question like this Setting WPF image source in code

the answer boils down to

ImgOnForm.Source = new BitmapImage(new Uri(@"/yourApp;component/img.png", UriKind.Relative));
like image 58
JoshVarga Avatar answered Apr 11 '26 00:04

JoshVarga


Here is what worked for me :

chemin = "/Assets/Images/" + nomFichier + ".gif";
MonImage.Source = new BitmapImage(new Uri(base.BaseUri, chemin));

None of the suggestions I found on the forums worked (I had no image, or an ArgumentException). But with "base.BaseUri" as first agument, it worked at last.

like image 35
Myosotis Avatar answered Apr 10 '26 23:04

Myosotis



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!