Bitmap Image/ Resource file problem


R

raylopez99

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
problem.

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 directory...is it the one having the .sln file?). But again
I prefer using the resources file if possible.

RL

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

g.DrawImage(pgn0, srcRect0);
}
using (Bitmap pgn1 = new
Bitmap(global::MDIForms.Properties.Resources.MyImageFile))
{
Rectangle srcRect1 = new Rectangle(157, 169, 100,
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
{
get
{
object obj = ResourceManager.GetObject("MyImageFile",
resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
 
Ad

Advertisements

R

raylopez99

I have a minor problem locating an image file to load as a Bitmap.

I found the problem. The Visual Studio Express does not have a
resource editor. I had built "Nude Susan" using the Visual Studio
2005 Professional edition, then, half way through the project,
'upgraded' (or downgraded) to the Free Visual Studio 2008 version,
hence the problem.

See here:

http://www.hotsolder.com/2007/12/resource-editing-for-visual-studio-express..html

Which also recommends some freeware solutions. For this particular
project of mine, I might resort to simply storing the graphics in a
temporary directory rather than a resource file--inelegant but works.

RL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top