How can I include an image as a Resource in my project?
<p>I want to add an image as a resource in my project so that I can reference it for programmatically inserting into a range in a spreadsheet. </p>

<p>I added the image by right-clicking the project and selecting Add > Existing Item...</p>

<p>I hoped that the image (.png file) would then be available using this code:</p>

<pre><code>var logoRange = _xlSheet.Range[
                    _xlSheet.Cells[1, LOGO_FIRST_COLUMN], 
                    _xlSheet.Cells[5, LOGO_LAST_COLUMN]];
//System.Drawing.Bitmap logo = 
    //ReportRunner.Properties.Resources.pa_logo_notap.png;
System.Drawing.Image logo = 
    ReportRunner.Properties.Resources.pa_logo_notap.png;
_xlSheet.Paste(logoRange, logo);
</code></pre>

<p>...but using either Bitmap or Image, I get, "'ReportRunner.Properties.Resources' does not contain a definition for 'pa_logo_notap'"</p>

<p>This seemed like sensible code based on what I read <a href="https://stackoverflow.com/questions/154262/example-code-required-for-how-to-access-embedded-net-image-resources-in-c-sharp">here</a>, but it seems that the image has to be explicitly marked as a resource for this to work. How do I accomplish that?</p>

<h2>UPDATE</h2>

<p>I tried this:</p>

<pre><code>System.Drawing.Image logo = (System.Drawing.Image)ReportRunner.Properties.Resources.ResourceManager.GetObject("pa_logo_notag.png");
_xlSheet.Paste(logoRange, logo);
</code></pre>

<p>...but not only did I get a confirmation msg about the item being pasted not being the same size and shape as the place where it was being inserted, and did I really want to do that, it also inserted some seemingly unrelated text ("avgOrderAmountCell.Style") instead of the image.</p>

<h2>UPDATE 2</h2>

<p>Okay, I tried this:</p>

<pre><code>Assembly myAssembly = Assembly.GetExecutingAssembly();
System.Drawing.Image logo = (System.Drawing.Image)myAssembly.GetName().Name + ".pa_logo_notap.png";
Clipboard.SetDataObject(logo, true);
_xlSheet.Paste(logoRange, logo);
</code></pre>

<p>...but get, "<em>Cannot convert type 'string' to 'System.Drawing.Image</em>' on the second line of that code.</p>

<h2>UPDATE 3</h2>

<p>This works:</p>

<pre><code>private System.Drawing.Image _logo;
. . .
_logo = logo; // logo (the image) is passed in an overloaded constructor
. . .
var logoRange = _xlSheet.Range[
    _xlSheet.Cells[1, LOGO_FIRST_COLUMN], _xlSheet.Cells[6, 
    LOGO_LAST_COLUMN]];
Clipboard.SetDataObject(_logo, true);
_xlSheet.Paste(logoRange, _logo);
</code></pre>

<p>...but I'm not crazy about it, because I'm using an image that is on a form, and passing the image to this class's constructor. Passing images around seems kind of goofy when it should be possible to store the image as a resource and just load the resource. I still haven't gotten that methodology to work, though...</p>

<h2>UPDATE 4</h2>

<p>I reckon I'll just stick with what I've got (in Update 3), kludgy as it is, because this:</p>

<pre><code>Assembly myAssembly = Assembly.GetExecutingAssembly();
Stream myStream = 
    myAssembly.GetManifestResourceStream(myAssembly.GetName().Name + 
    "pa_logo_notap.png");
Bitmap bmp = new Bitmap(myStream);
Clipboard.SetDataObject(bmp, true);
_xlSheet.Paste(logoRange, bmp);
</code></pre>

<p>...fails with, "<em>Value of 'null' is not valid for 'stream'</em>"</p>