title: Loading images from a relative path
body: <p>I'm making a Blackjack game for a project in college (semester-long) and I've hit a road block that I can't seem to get over.</p>
  
  <p>I'm trying to load the card images so they can be displayed onscreen, but I've been having <em>very</em> little luck in doing so. I've got absolute references down; I can load from those, but any attempt to load from a relative path fails. The project must be standalone; I can't instruct my professor to copy these images onto the root.</p>
  
  <pre><code>#if FROMDISK
          Uri myUri = new Uri(@"C:\cards\" + getFilename(r, s, "png"), UriKind.Absolute);
          PngBitmapDecoder decoder2 = new PngBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
          BitmapSource bmp = decoder2.Frames[0];
  #else
          System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
          Stream myStream = myAssembly.GetManifestResourceStream("Blackjack." + getFilename(r, s, "png"));
          BitmapImage bmp = new BitmapImage();
          bmp.StreamSource = myStream;
  #endif
          // Draw the Image
          im.Source = bmp;
          im.Stretch = Stretch.Uniform;
          im.Width = CARD_WIDTH;
  </code></pre>
  
  <p><a href="https://github.com/vermiculus/se-blackjack/blob/master/proj/Blackjack!/MainWindow.xaml.cs#L110" rel="noreferrer">(Context)</a></p>