WPF Image Dynamically changing Image source during runtime WPF Image Dynamically changing Image source during runtime wpf wpf

WPF Image Dynamically changing Image source during runtime


I can think of two things:

First, try loading the image with:

string strUri2 = String.Format(@"pack://application:,,,/MyAseemby;component/resources/main titles/{0}", CurrenSelection.TitleImage);imgTitle.Source = new BitmapImage(new Uri(strUri2));

Maybe the problem is with WinForm's image resizing, if the image is stretched set Stretch on the image control to "Uniform" or "UnfirofmToFill".

Second option is that maybe the image is not aligned to the pixel grid, you can read about it on my blog at http://www.nbdtech.com/blog/archive/2008/11/20/blurred-images-in-wpf.aspx


Hey, this one is kind of ugly but it's one line only:

imgTitle.Source = new BitmapImage(new Uri(@"pack://application:,,,/YourAssembly;component/your_image.png"));


Here is how it worked beautifully for me.In the window resources add the image.

   <Image x:Key="delImg" >    <Image.Source>     <BitmapImage UriSource="Images/delitem.gif"></BitmapImage>    </Image.Source>   </Image>

Then the code goes like this.

Image img = new Image()img.Source = ((Image)this.Resources["delImg"]).Source;

"this" is referring to the Window object