NetImageLibrary
NetImageLibrary copied to clipboard
png bit depth settings
my png's bit depth is 24, but SavePng
method is 32, which increase the size of the image
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.
thanks @fschultz , is there any way to make ColorDepth self-adaption
, because not all the png
is 24 bit, right?