سؤال

I was using the FreeImageNET libary to Quantize my Bitmap as

using (FreeImageAPI.FreeImageBitmap fiBitmap = FreeImageAPI.FreeImageBitmap.FromHbitmap(bmp.GetHbitmap()))
            {
                if (fiBitmap.ColorDepth > 24)
                {
                    fiBitmap.ConvertColorDepth(FreeImageAPI.FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP);
                }

                //quantize using the NeuQuant neural-net quantization algorithm 
                fiBitmap.Quantize(FreeImageAPI.FREE_IMAGE_QUANTIZE.FIQ_NNQUANT, 256);


                fiBitmap.Save("test_z.png", FreeImageAPI.FREE_IMAGE_FORMAT.FIF_PNG, FreeImageAPI.FREE_IMAGE_SAVE_FLAGS.PNG_Z_BEST_COMPRESSION);

                //fiBitmap.Save(ms, FreeImageAPI.FREE_IMAGE_FORMAT.FIF_PNG, FreeImageAPI.FREE_IMAGE_SAVE_FLAGS.PNG_Z_DEFAULT_COMPRESSION);
            }

This gives me a PNG-8, with a palette of 256 colors. Using Photoshop I found, I could further reduce the size if I used Adaptive Algorithm with reduced color palette say 128, 64, 16 etc. Reopening it again shows Photoshop fills in grey levels in those remaining(higher) indexes.

I cannot get FreeImageAPI.FreeImageBitmap.Quantize() to churn out a similar PNG, with limited palette, a la PIL convert() where you can specify both the algorithm and the palette size.

Thanks.

هل كانت مفيدة؟

المحلول

Ended up re-implementing quantization by using open-source codes from the Internet.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top