libgdiplus
libgdiplus copied to clipboard
PNG images with 16bpp aren't supported by libgdiplus
Related https://github.com/dotnet/corefx/issues/33951
I'm using System.Drawing.Common on Ubuntu, there is exception when loading a 16bit png file.
** (process:10021): WARNING **: 17:41:57.195: PNG images with 16bpp aren't supported by libgdiplus.
Unhandled Exception: System.ArgumentException: Image format is unknown.
at System.Drawing.Bitmap..ctor(String filename, Boolean useIcm)
at debug.Program.Main(String[] args) in /home/user/debug/Program.cs:line 10
Ubuntu versions: OS: Ubuntu 18.04.1 LTS Kernel: 4.15.0-39-generic x86_64 dotnet: 2.1.500 System.Drawing.Common: 4.6.0-preview.18571.3 libpng16: 1.6.34-1ubuntu0.18.04.1 libgdiplus: 4.2-2
However, there is no exception when I test the same image on CentOS.
CentOS Versions: OS: CentOS 7 Kernel: 3.10.0-514.21.1.el7.x86_64 dotnet: 2.1.500 System.Drawing.Common: 4.6.0-preview.18571.3 libpng: libpng-1.5.13-7.el7_2.x86_64 libgdiplus: libgdiplus-2.10-10.el7.x86_64
Sample code:
using System;
using System.Drawing;
namespace debug
{
class Program
{
static void Main(string[] args)
{
Bitmap bmp = new Bitmap("16bit_Gray16.png");
Console.WriteLine(bmp.Height);
}
}
}
Sample image:

I guess it should be fixed here https://github.com/mono/libgdiplus/blob/bbd132a0ad01b1f514836b40fe49e23e0ef6b3da/src/pngcodec.c#L459
it should be if (channels * bit_depth >= 48) {
@EgorBo so, does it mean that 48bpp is still not supported after the fixed? I have another image that can be load on CentOS while not on Ubuntu.
libpng warning: iCCP: known incorrect sRGB profile
** (process:12405): WARNING **: 11:26:57.707: PNG images with 48bpp aren't supported by libgdiplus.
Unhandled Exception: System.ArgumentException: Image format is unknown.
at System.Drawing.Bitmap..ctor(String filename, Boolean useIcm)
at debug.Program.Main(String[] args) in /home/user/debug/Program.cs:line 10

Any progress on this one?
My case:
** (process:1): WARNING **: PNG images with 64bpp aren't supported by libgdiplus.
Due to PNG images with 48bpp aren't supported by libgdiplus issue on Linux I switched my .NET Core image resizing implementation to use ImageSharp based on this article. Had to install libgdiplus into my docker image though, even for ImageSharp.
(Partial) support for 48bpp and 64bpp PNG images was implemented in #49 about two years ago. Are you using the latest version of libgdiplus (currently 6.0.1)?
I checked a log, and Amazon Linux amzn2-ami-ecs-hvm-2.0 (apparently based on Debian) is downloading is version 4.2-1+b1.
Guys, is this correct? https://packages.ubuntu.com/bionic/libgdiplus The latest version is apparently 4.2.2 (not 6.0.x) on ubuntu 18.04 lts.
Yes. Use the Mono Ubuntu repositories to get a newer version of libgdiplus.
Yes. Use the Mono Ubuntu repositories to get a newer version of libgdiplus.
Do you mean install mono to get libgdiplus 6? I'm using libgdiplus with aspnet core in a production environment to scale images. Installing mono with it feels a bit much
You don't need to install Mono. But the package repositories for Mono contain an updated version of libgdiplus.
Alternatively, Ubuntu 20.04 should ship with libgdiplus 6.