-2
A
回答
0
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
)。
相關問題
- 1. 如何快速將圖像文件路徑列表轉換爲位圖列表?
- 2. 將visual C++圖像文件路徑轉換爲xml
- 3. 如何將圖像的文件路徑轉換爲實際圖像?
- 4. 將圖像路徑轉換爲http url
- 5. 如何將位圖轉換爲圖像
- 6. 將WPF路徑轉換爲位圖文件
- 7. C# - 如何將圖像轉換爲8位彩色圖像?
- 8. 如何轉換爲繪畫圖像轉換爲位圖
- 9. 轉換和字符串(圖像的路徑)到位圖obj
- 10. 轉換PDF文件爲圖像 - VB/C#
- 11. 使用JQuery將XML圖像路徑轉換爲圖像
- 12. 如何將文件路徑轉換爲android中的文件探索視圖
- 13. 如何將Assembly.CodeBase轉換爲C#中的文件系統路徑?
- 14. 如何使用ALAssetsLibrary將圖像路徑轉換爲uiimage
- 15. 如何將base64圖像路徑轉換爲使用jquery的真實路徑。
- 16. 如何將SVG圖像「路徑」轉換爲單獨的PNG圖像?
- 17. 如何從OI文件管理器路徑獲取位圖圖像?
- 18. 如何將位圖圖像轉換爲CIELab圖像?
- 19. 如何在viewpager中旋轉圖像並在現有路徑上保存位圖
- 20. 圖像路徑文件夾
- 21. 圖像的文件路徑
- 22. 如何將24位圖像轉換爲16位rgb565位圖?
- 23. 如何在Java中將16位.tiff圖像轉換爲8位.tiff圖像?
- 24. 如何在OpenCV中將16位圖像轉換爲32位圖像?
- 25. 如何從路徑中裁剪圖像?
- 26. 如何將位圖轉換爲intptr C#
- 27. Python模塊路徑如何轉換爲文件系統路徑?
- 28. 如何將物理路徑轉換爲虛擬路徑在C#
- 29. 如何將位圖數據轉換爲AS3中的圖像文件?
- 30. 如何將索引圖像轉換爲C#中的RGB圖像?
反斜槓:\ n形成一個換行符。通過將它們加倍來逃避它們,或者在字符串前加@。 – dlatikay