title: How do I get an image from a file in a silverlight C# library into a writeable bitmap without using ImageLoaded event?
body: <p>I need to have an image in my silverlight library and load it into a bitmap.  I want to just refer to it like a resource, but not sure how to go about it.  I don't have any xaml at all in this library, but what I read seems to indicate I need to do it with xaml.  </p>
  
  <p>Here is how I did it in a sample solution using the imageLoaded event.  (you know how silverlight just loves async stuff!)  The image properties is set to resource/copy always.</p>
  
  <pre><code>public partial class MainPage : UserControl
  {
      WriteableBitmap myIcon = new WriteableBitmap(100, 100);
  
      public MainPage()
      {
          InitializeComponent();
          LoadImages();
  
      }
  
      public void LoadImages()
      {
          BitmapImage bmi = new BitmapImage();
          bmi.ImageOpened += ImagesLoaded;
          bmi.CreateOptions = BitmapCreateOptions.None;
          bmi.UriSource = new Uri(App.Current.Host.Source, "/ClientBin/HouseLogo.png");
      }
  
  
      public void ImagesLoaded(object sender, RoutedEventArgs e)
      {
          BitmapImage bm = (BitmapImage)sender;
          myIcon = new WriteableBitmap(bm);
      }
  
      private void btnPdf_Click(object sender, RoutedEventArgs e)
      {
          PDFdoc doc = new PDFdoc(32.0, 32.0, myIcon );
      }
  }
  </code></pre>