title: how to add png for a image in code for silverlight?
body: <p>Try to create a image in code as below:</p>
  
  <pre><code>sp = new StackPanel() { Orientation = Orientation.Horizontal };
  Image myImage = new Image() { HorizontalAlignment = HorizontalAlignment.Left, Width = 16, Height = 16, Margin = new Thickness(1, 0, 0, 0) };
  MyImage.Source = new BitmapImage(new Uri("/MyAssembly;component/folder/image1.png", UriKind.RelativeOrAbsolute));
  sp.Children.Add(MyImage);
  </code></pre>
  
  <p>then run the app, the image does not display. Check the data with Fiddler and got 404 error. The source for above image is something like:</p>
  
  <pre><code>http://localhost:80/MyAssembly;component/folder/image1.png
  </code></pre>
  
  <p>but this image is complied into an assembly MyAssembly. </p>
  
  <p>It is okay to get the image xaml from the assembly with following markup:</p>
  
  <pre><code>&lt;Image Source="/MyAssembly;component/folder/image1.png"/&gt;
  </code></pre>
  
  <p>Confused. Not sure why. How to get dynamic image in code?</p>
  
  <p><strong>Updated:</strong> Thanks for information form Clemens. Try following code:</p>
  
  <pre><code>sp = new StackPanel() { Orientation = Orientation.Horizontal };
  ImageSourceConverter converter = new ImageSourceConverter();
  Image myImage = new Image() { HorizontalAlignment = HorizontalAlignment.Left, Width = 16, Height = 16, Margin = new Thickness(1, 0, 0, 0) }; 
  MyImage.Source = (ImageSource)converter.ConvertFromString("/MyAssembly;component/folder/image1.png");
  sp.Children.Add(MyImage);
  </code></pre>
  
  <p>the result same as before. message from Fiddler:
  The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.</p>
  
  <p>The resource for this still is</p>
  
  <pre><code> http://localhost:80/MyAssembly;component/folder/image1.png.
  </code></pre>