NetImageLibrary icon indicating copy to clipboard operation
NetImageLibrary copied to clipboard

png bit depth settings

Open quaider opened this issue 7 years ago • 2 comments

my png's bit depth is 24, but SavePng method is 32, which increase the size of the image

quaider avatar Oct 10 '17 05:10 quaider

Internally the library works with rgba-format. Unfortunately the PNG-encoder in GDI+ ignore the Encoder.ColorDepth parameter which otherwise would have been a good idea to use. The solution is to copy the bitmap image onto a new canvas with the required pixel format and then saving it:

    // Assuming that "image" is a KalikoImage object
    Bitmap target = new Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
    Graphics g = Graphics.FromImage(target);
    g.DrawImage(image.GetAsBitmap(), new Point(0, 0));
    target.Save("24bit.png", ImageFormat.Png);

Adding a pixel format aware save function would be a good feature to add, so I'm adding this to the backlog.

fschultz avatar Oct 11 '17 20:10 fschultz

thanks @fschultz , is there any way to make ColorDepth self-adaption , because not all the png is 24 bit, right?

quaider avatar Oct 13 '17 01:10 quaider