By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,906 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,906 IT Pros & Developers. It's quick & easy.

Bitmap Image/ Resource file problem

P: n/a
I have a minor problem locating an image file to load as a Bitmap.

A resource file "NudeSusan.jpeg" (which I think is actually a bmp
file, originally taken from a jpeg of model Susan Spears) is loaded
onto the "Resources" tree of the Visual Studio Solutions Explorer, and
correctly works. However, another file, "MyImageFile.png" (which is
also a bmp file, sorry for the confusion, but originally was a png
file), does not work.

How can I get "MyImageFile.png" registered? I thought perhaps the
solution was to add the method found below***, from the bowels of the
Resources.Designer.cs file, akin to what is there for NudeSusan, but
there's more to it than that (adding this method will allow you to
compile but you get a runtime exception). There's some other code I
notice that the Wizard adds, but how do you click to get the wizard to
add the image file? For NudeSusan I added the image as an icon file I
believe--is that the way to always add images to the resource file?
But how did I get the "MyImageFile.png" added to the resources tree?
Very confusing.

This should be an easy answer--it's some click and point mechanics

As a last resort, I can add this file via a 'path', but I prefer not
to do it that way, however, if there's a quick 'forward' slash'
shorthand for adding the bmp file via a path that's the default
directory path for the solution (and forgive my ignorance, but which
directory would that be? There's so many of them created in the
solutions it the one having the .sln file?). But again
I prefer using the resources file if possible.


using (Bitmap pgn0 = new
Bitmap(global::MDIForms.Properties.Resources.NudeS usan))
Rectangle srcRect0 = new Rectangle(57, 69, 100, 100);

g.DrawImage(pgn0, srcRect0);
using (Bitmap pgn1 = new
Bitmap(global::MDIForms.Properties.Resources.MyIma geFile))
Rectangle srcRect1 = new Rectangle(157, 169, 100,

g.DrawImage(pgn1, srcRect1);
//I added this, similar to what's already there (from the Wizard) for
NudeSusan, but doesn't quite work:

internal static System.Drawing.Bitmap MyImageFile
object obj = ResourceManager.GetObject("MyImageFile",
return ((System.Drawing.Bitmap)(obj));
Jul 30 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.