Im am pretty new to the c# language only 3months into my course and im have alot of trouble calling a bitmap for my project
public void DrawHand(Graphics cardSpace1, Graphics cardSpace2)
{
playersHand.GetCards();
cardpic1 = playersHand.Card1FileName;
cardpic2 = playersHand.Card2FileName;
card1 = new Bitmap("@../CardDeck/" + (cardpic1) + ".jpg");
card2 = new Bitmap("@../CardDeck/" + (cardpic2) + ".jpg");
cardSpace1.DrawImage(card1, 0, 0, 0, 0);
cardSpace2.DrawImage(card2, 0, 0, 0, 0);
GetScore();
}
dats my code the address im pretty sure is right the folder is saved in the bin folder wit debug.
Any help will be much appreciated
Loading
Dr SpackPosted Dec 11, 2007, 1:12 PM
I have checked and I see at the moment two possibilities:
1. The framework cannot read the jpg, because the file is simply not a jpeg-file. I don't think that you did make that mistake!? ;)
2. The file does simply not exist at the position you have given.
The strange thing is that the framework should throw a FileNotFoundException, but it does not. It throws an ArgumentException ('Unknown parameter').
I would check the current directory with: string currentDir = System.IO.Directory.GetCurrentDirectory();.
Then you will see if your relative path is the correct one.
Maybe it is best if you create a static variable (encapsulated in a property) which contains the path to your graphics folder.
Good Luck…
Rachel FinanPosted Dec 11, 2007, 11:49 AM
Dr SpackPosted Dec 11, 2007, 7:42 AM
the @ must be before the " and the slash / should be a back slash \
card1 = new Bitmap( @"..\CardDeck\" + cardpic1 + ".jpg" );
I hope the answer does solve your problem.