libgdiplus icon indicating copy to clipboard operation
libgdiplus copied to clipboard

PNG images with 16bpp aren't supported by libgdiplus

Open lennylxx opened this issue 6 years ago • 10 comments

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: 16bit_gray16

lennylxx avatar Dec 11 '18 06:12 lennylxx

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 avatar Dec 11 '18 18:12 EgorBo

@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

48bit_r16g16b16

lennylxx avatar Dec 12 '18 03:12 lennylxx

Any progress on this one? My case: IMG_0102

** (process:1): WARNING **: PNG images with 64bpp aren't supported by libgdiplus.

djbios avatar May 17 '19 13:05 djbios

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.

xhafan avatar Jul 25 '19 09:07 xhafan

(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)?

qmfrederik avatar Aug 09 '19 19:08 qmfrederik

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.

xhafan avatar Aug 16 '19 07:08 xhafan

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.

elgerm avatar Apr 14 '20 10:04 elgerm

Yes. Use the Mono Ubuntu repositories to get a newer version of libgdiplus.

qmfrederik avatar Apr 14 '20 10:04 qmfrederik

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

elgerm avatar Apr 14 '20 10:04 elgerm

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.

qmfrederik avatar Apr 14 '20 10:04 qmfrederik