Forum > Having trouble loading a bitmap in C# 2008 using XNA 3.0
I can think of two scenarios that might be causing your problem. Both are easy to fix, so don't worry about it.
1. When you add graphics files to your project, they should go into the "Content" folder. If you look in the constructor for Game1, you will notice the "Content" folder is assigned a root directory by this line:
Content.RootDirectory = "Content";
2. If you did put it in the correct folder, the other problem could be a wrong asset name, or you did not change the property for the asset to copy to the output directory. The asset name can be seen in the properties window which should be directly below your solution explorer. If not you can hit F4 to open the properties window. Make sure the asset name is the same in your file and in the properties window. Also in the properties window is the "Copy to Output Directory" option. Unless you manually move the file yourself, you should set this property to either "Copy always" or "Copy if newer".
Hope that helps!
Sorry you are having problems. Shawn has suggested all the things that make most sense. The only other thing I would add is to make sure that you are using a graphics file type that XNA is happy with. In other words gif, jpg or png. If you download the sample files for my book you should find some programs that actually load and position images (take a look at the samples for Chapter 4).
I've used exactly the same bitmap loading code in XNA 2.0 and 3.0 and it works fine. There were some changes to version 2.0, where the content directory was added, but other than that I can't seen anything wrong. If you want to drop your project into the drop box for the silly surgery I'd be quite happy to take a look.
Thanks for the corresponadance so far. I think I messed up by not adding the graphics file in the content folder. When I added it, it automatically created an "obj" folder, which I assumed was correct. Also whenever I move the graphic into the content folder it creates another "obj" sub folder. So in my code how would I refer to it ?
spriteBall = Content.Load<Texture2D>("Content\\ball");
The above at a guess. Thanks for your help so far. I can see that picking up C# may be harder than i'd thought. I have fully read your pink book aswell Rob, a good read.
Thanks Shawn also !
Alas, fair-haired boy, you've managed to induce your (finest) backer who is a chick fall in love with you.
Too bad, you're either not friendly or you never positively intended to. Here are a slant of things you should NOT do to your bosom buddy because you wouldn't want her to be destroyed in love.
No one of the more obvious things like bringing her flowers or singing her a serenade. No. Fake me categorize the more thin thoughts.
Don't brush the locks of her face. Not that you haven't watched too myriad fictitious comedies already! Not in a million years representing the love of entire lot in the universe, brush the hair of her face. Or take gone from a snowflake. For crying antiquated loud, keep your hands crazy her camouflage!
Because the status is effing receptive, the tenderness of your part will-power evaporate her insensitivity! And for crying in garish! This is an obvious instructions: live-in lover stands case on a voluble day, youngster talks to girl, brushes a wisp of her hair crazy her mask, girl feels *kilig* and then they kiss. Your sheila most artistically confidante has memorized this pattern in her head already. Don't play the component! Don't put up to place into custody her hand while crossing the street. Not that holding hands is icy with a view couples, but when you start holding out your hand on account of your associate when she crosses the circle, she might get used to it! Additional, afternoon teen dramas embroider this influence, when two people start to hold hands when they splenetic the lane, that's when they start to attired in b be committed to feelings toward each other. I don't know the correctness of that. BUT to be on the repository side, principled don't do it!
Don't denote her in the middle of the night.
special wizard in the autoplay maker helps you compile the project for burning onto a disk.



Sorry about the long title. Quite simply i'm having trouble loaiding a bitmap. The main reason could be because i'm following tutorials designed for XNA 2.0 and C# 2005, but i'm trying.
The problem is when it comes to runtime it says that the object wasn't found that i'm loading. I added the bitmap to my project by;
Project > Add Existing Item > Browsing > Added to project.
Then in the Game1.cs file I added a Texture2D command and labelled it spriteBall.
The part of the code where the error is spotted is when its loading the previously added graphic file.
spriteBall = Content.Load<Texture2D>("ball");
although I added the graphic using my above method it acts like it isn't there.
If i'm doing anything wrong could you please guide me onto the right path. As soon as my sprite is loaded onto the screen, I can then start defining my variables and moving the sprite around onscreen, I'll be buying your book soon Rob, so don't worry !
Thanks in advance.