Home Unable to create Bitmap from disk file on Linux
Reply: 1

Unable to create Bitmap from disk file on Linux

Tudor
1#
Tudor Published in 2018-02-14 10:55:43Z

I'm referencing CoreCompat.System.Drawing.v2 as well as runtime.linux-x64.CoreCompat.System.Drawing from a .NET Core project and doing the following:

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

I've checked that the path is correct at runtime. On Windows this works fine, but on Debian I am getting:

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

I've installed libgdiplus, but no luck.

Using System.Drawing.Common gives the following error:

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

I've read somewhere that this could be due to the image size being too large, but in my case it's a 1920x1080 bmp so not out of the ordinary.

Chris Smith
2#
Chris Smith Reply to 2018-02-15 03:30:51Z

You need to use the correct path separator for the current environment.

In your case, you're attempting to concatenate a path using the Windows separator (backslash). However, Linux uses a forward-slash as its path separator.

So on Windows, your path looks like this: ..\images\image_0.bmp

But on Linux, your path would actually be this: ../images/image_0.bmp

In order to get your code working in all supported environments, use the Path.DirectorySeparatorChar value as your delimiter.

In that case, your code becomes the following:

var delim = Path.DirectorySeparatorChar;
Bitmap frame = new Bitmap($"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}{delim}images{delim}image_0.bmp");
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.296618 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO