2017-05-09 104 views

回答

0

你想要Image.FromFile Method

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."); 
} 
+0

使用'位圖(字符串)'什麼錯誤 - 字符串是文件路徑?只是好奇 – FakeCaleb

+0

*構造函數*或使用Image.FromFile沒有任何問題。 OP雖然忘了逃脫'\' –

+0

@FakeCaleb沒什麼好說的。我的答案是過度設計的,用例。 EpicKip的答案將是最合適的。 –

2

這通常只是起作用,您是否使用轉義字符來逃避轉義字符? 例子:

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)。

相關問題