Reputation: 75
I have a problem with new bitmap, it says that parameter is not valid.
Bitmap image = new Bitmap("..//..//images//brick.jpg");
I have folder images in my project which contains brick.jpg
.
In other examples the same way of using works but here I have a problem.
Do you have any idea what is happening and what can cause this problem ?
I am using a picture dimension type 2^n
. Picture is 4kb
.
This is a visual studio project, not a web application.
It is a runtime error.
Solution:
This helped me because it was in a wrong place Console.WriteLine(new System.IO.FileInfo("..//..//images//brick.jpg").FullName);
thanks
Upvotes: 2
Views: 12452
Reputation: 17185
Be aware that the current directory when running from within visual studio is, by default, not the path of the executable, but the visual Studio project path. Go to Project properties, Debugging and set the current directory for executing the application correctly.
Be also aware that the Bitmap constructor throws any type of exception for any type of error. The type or message you'll get does not tell you anything about the cause of the error. It could be "file not found" (the most likely here) but also "image is unreadable" or similar Problems.
Upvotes: 1
Reputation: 3702
Are you sure the image is located in that directory? (Two dirs up from where your exe is running and then in the images dir). If you're not sure on where to place the file, you can print the path with:
Console.WriteLine(new System.IO.FileInfo("..//..//images//brick.jpg").FullName);
Upvotes: 5