title: How to get a System.Drawing.Image object from image which build action is marked as Resource?
body: <p>I have a wpf app,and got a image useful for codebehind which's location in the project is something like "projectName\images\pp.png" and its build action is "Resource"(Node:<strong>not Embedded Resource</strong>).
  I need a System.Drawing.Image object in the codebehind.
  I tried these methods:</p>
  
  <p>1.</p>
  
  <pre><code>var img = new BitmapImage(new Uri(@"\images\pp.png", UriKind.Relative));
  var stream = img.StreamSource;
  System.Drawing.Image needObj = Image.FromStream(stream);
  </code></pre>
  
  <p>i got a null stream,so it's not work.</p>
  
  <p>2.</p>
  
  <pre><code>private static System.IO.Stream getResource(string name)
  {
      var assembly = Assembly.GetExecutingAssembly();
      string resName = assembly.GetName().Name + ".g.resources";
      return assembly.GetManifestResourceStream(resName);
  }
  var stream = getResource(@"\images\pp.png");
  System.Drawing.Image needObj = Image.FromStream(stream);
  </code></pre>
  
  <p>i got an UnmanagedMemoryStream object,and an InvalidArgument exception occurred while calling "Image.FromStream(stream)" .</p>
  
  <p>Could anyone tell me why the two methods above not working or how to achieve it ?</p>