title: How to add PNG and JPG at runtime
body: <p>I am using C# and WPF. I want to add a PNG and JPG at runtıme to an image source but I get  an exception that says:  </p>
  
  <p><code>Can not implicitly add convert type string to Sytem.Windows.Media.imageSource</code></p>
  
  <pre><code>using System.IO;                      //for : input - output
  using Microsoft.Win32;                //For : OpenFileDialog / SaveFileDialog
  using System.Windows.Media.Imaging;   //For : BitmapImage etc etc
  
  
  &lt;Image x:Name="img" Margin="9,13.5,6,0.5" Source="Laugh.ico"&gt; 
  
  
  private void ac(object sender, RoutedEventArgs args)
  {       
      OpenFileDialog dlg = new OpenFileDialog();
      // Configure open file dialog box
      dlg.FileName = "Document"; // Default file name
      dlg.DefaultExt = ".PNG"; // Default file extension
      dlg.Filter = " (.PNG)|*.PNG"; // Filter files by extension
  
      // Show open file dialog box
      Nullable&lt;bool&gt; result = dlg.ShowDialog();
  
      // Process open file dialog box results
      if (result == true)
      {
          // Open document
          string filename = dlg.FileName;
          img.Source=filename;
      }
  }
  </code></pre>