Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting URI -> object -> imagesource

Tags:

c#

uri

wpf

img = new Image()
{
    Height = 150,
    Stretch = System.Windows.Media.Stretch.Fill,
    Width = 200
};
img.Source = (ImageSource) new ImageSourceConverter()
                .ConvertFromString("/FirstDemo;component/Images/Hero.jpg");

After hours of research, trying to assign an image to an image class. I came across this way of assigning an image. I have absolutely no idea why I this code does not run. It does not get any compiler error though.. Odd. its 11 25 pm here btw

like image 660
Bug Avatar asked Nov 22 '25 23:11

Bug


1 Answers

Do it this way:

img = new Image();
img.Height = 150;
img.Width = 200;
img.Stretch = Stretch.Fill;
img.Source = new BitmapImage(new Uri("/FirstDemo;component/Images/Hero.jpg"));
like image 163
MyKuLLSKI Avatar answered Nov 25 '25 13:11

MyKuLLSKI