Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2008

Tip: Looking for answers? Try searching our database.

Bitmap Image/ Resource file problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
raylopez99 - 30 Jul 2008 21:39 GMT
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));
           }
       }
raylopez99 - 31 Jul 2008 10:33 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.