Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法在Linux上从磁盘文件创建位图_C#_.net_.net Core - Fatal编程技术网

C# 无法在Linux上从磁盘文件创建位图

C# 无法在Linux上从磁盘文件创建位图,c#,.net,.net-core,C#,.net,.net Core,我正在引用.NET核心项目中的CoreCompat.System.Drawing.v2以及runtime.linux-x64.CoreCompat.System.Drawing,并执行以下操作: Bitmap frame = new Bitmap($"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\images\\image_0.bmp") var delim = Path.DirectorySeparato

我正在引用.NET核心项目中的
CoreCompat.System.Drawing.v2
以及
runtime.linux-x64.CoreCompat.System.Drawing
,并执行以下操作:

Bitmap frame = new Bitmap($"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\images\\image_0.bmp")
var delim = Path.DirectorySeparatorChar;
Bitmap frame = new Bitmap($"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}{delim}images{delim}image_0.bmp");
我已经检查了路径在运行时是否正确。在Windows上这很好,但在Debian上我得到:

Unable to update the static FcBlanks: 0x0600
Unable to update the static FcBlanks: 0x0601
Unable to update the static FcBlanks: 0x0602
Unable to update the static FcBlanks: 0x0603
Unable to update the static FcBlanks: 0x06dd
Unable to update the static FcBlanks: 0x070f
Unable to update the static FcBlanks: 0x2028
Unable to update the static FcBlanks: 0x2029
Unable to update the static FcBlanks: 0xfff9
Unable to update the static FcBlanks: 0xfffa
Unable to update the static FcBlanks: 0xfffb

Unhandled Exception: System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
at System.Drawing.GDIPlus.CheckStatus(Status status)
at System.Drawing.Bitmap..ctor(String filename, Boolean useIcm)
at TestVideoConvert.TestVideoConvert.Create() in /home/osboxes/Downloads/Test2/TestVideoConvert/TestVideoConvert.cs:line 44
at ImageResizeNetCore.Program.Main(String[] args) in /home/osboxes/Downloads/Test2/ImageResizeNetCore/Program.cs:line 15
我安装了
libgdiplus
,但运气不好

使用
System.Drawing.Common
会产生以下错误:

Unhandled Exception: System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(String filename, Boolean useIcm)
at TestVideoConvert.TestVideoConvert.Create() in /home/osboxes/Downloads/Test2/TestVideoConvert/TestVideoConvert.cs:line 44
at ImageResizeNetCore.Program.Main(String[] args) in /home/osboxes/Downloads/Test2/ImageResizeNetCore/Program.cs:line 15

我在某个地方读到过,这可能是因为图像大小太大,但在我的例子中,它是1920x1080 bmp,因此不寻常。

对于当前环境,您需要使用正确的路径分隔符

在本例中,您正试图使用Windows分隔符(反斜杠)连接路径。但是,Linux使用正斜杠作为其路径分隔符

因此,在Windows上,您的路径如下:…\images\image\u 0.bmp

但在Linux上,您的路径实际上是:../images/image\u 0.bmp

为了使代码在所有受支持的环境中工作,请使用Path.directoryseportorchar值作为分隔符

在这种情况下,您的代码如下所示:

Bitmap frame = new Bitmap($"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\images\\image_0.bmp")
var delim = Path.DirectorySeparatorChar;
Bitmap frame = new Bitmap($"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}{delim}images{delim}image_0.bmp");

你也参考了runtime.linux-x64.corecompt.System.Drawing包吗?@Evk:是的,我忘了提那个。我已经更新了问题。哦!我真是个白痴。事实上,我改用ImageSharp处理位图,但没有找到路径。我希望系统。图纸实际上给出了一个有意义的错误。。。