Whats wrong displaying this image?
PictureBox image = new PictureBox();
image.Image = new Bitmap("grass.jpg");
In my project, I added this image named grass.jpg. This code throws this exception at run time: "Parameter is not val开发者_Go百科id."
In the properties of "grass.jpg" set Copy To Output Directory
to Copy if newer
. This will copy the image to the current directory of the program. The path "grass.jpg" is relative to the program, i.e. it is a file in the same directory as the program.
If you want to specify an absolute path to the image. You can use the path to the executable to build a path to the image like so:
string myDirectory = Path.GetDirectoryName(Application.StartupPath);
string imageFile = Path.Combine(myDirectory, "grass.jpg");
(But this is obviously the same path)
Probably the image couldn't be found. Try to specify a full path.
精彩评论