Bitmap bmp = new Bitmap("D:\1.jpg");
我得到的异常是:
参数无效。
我该如何解决?
Bitmap bmp = new Bitmap("D:\1.jpg");
通常情况下这样做是有效的,您是否使用转义字符来转义转义字符?例如:
Bitmap bm = new Bitmap("D:\\newfolder\\1.jpg");
//Notice the \\ the second \ escapes the first
或者像这样转义:
Bitmap bm = new Bitmap(@"D:\newfolder\1.jpg");
//Notice the @ in front of the string, that means ignore the escape characters
\n
)。try
{
Bitmap image1 = (Bitmap) Image.FromFile(@"C:\Documents and Settings\" +
@"All Users\Documents\My Music\music.bmp", true);
}
catch(System.IO.FileNotFoundException)
{
MessageBox.Show("There was an error opening the bitmap." +
"Please check the path.");
}
Bitmap(String)
- 其中字符串是文件路径,有什么问题吗?只是好奇。 - FakeCaleb \
。 - Panagiotis Kanavos