Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

png bit depth settings #16

Open
quaider opened this issue Oct 10, 2017 · 2 comments
Open

png bit depth settings #16

quaider opened this issue Oct 10, 2017 · 2 comments
Assignees
Milestone

Comments

@quaider
Copy link

quaider commented Oct 10, 2017

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

@fschultz
Copy link
Owner

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 fschultz self-assigned this Oct 11, 2017
@fschultz fschultz added this to the 3.0.3 milestone Oct 11, 2017
@quaider
Copy link
Author

quaider commented Oct 13, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants