无法在位图路径参数

时间:2018-05-26 20:55:12

标签: c# bitmap jpeg

我的项目中的文件夹中有一个jpg。我想制作一个位图,但是当我尝试引用jpg时,它说我的路径无效。

https://i.stack.imgur.com/dAWIG.jpg

控制台例外:

Unhandled Exception: System.ArgumentException: Illegal characters in path.
   at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.GetFullPathInternal(String path)
   at System.IO.Path.GetFullPath(String path)
   at System.Drawing.IntSecurity.UnsafeGetFullPath(String fileName)
   at System.Drawing.IntSecurity.DemandReadFileIO(String fileName)
   at System.Drawing.Bitmap..ctor(String filename)
   at ConsoleImageCompare.Compare.differance(String img1, String img2) in c:\users\user\documents\visual studio 2017\Projects\ConsoleImageCompare\ConsoleImageCompare\Compare.cs:line 22
   at ConsoleImageCompare.Program.Main(String[] args)  

1 个答案:

答案 0 :(得分:0)

原因是默认控制台应用程序指向bin / debug文件夹。所以你需要上升两级来获取文件

@"../../image/<Your File name>"

使用此