C# - How to change PNG quality or color depth
Solution 1:
Sorry for bringing up an old question, but I were solving the same problem today and found this page on MSDN: "Listing Parameters and Values for All Encoders". I hope it might be useful to refer to it there.
The article contains a sample program which outputs EncoderParameter
s supported by stock GDI+ image encoders, and PNG encoder supports no parameters according to it.
I'm not sure thought if one can take this for granted, or in some future version of gdiplus.dll
the PNG encoder might grow more support, and so one is supposed to check the encoder's capabilities at runtime.
In any case applying some explicit transformation on a source image appears to be more fruitful approach; I did not explore it yet though.
Solution 2:
I have taken 4 different PNGs, ranging in sizes from 2KB to 2.6MB. Using your code, I load them up and save them out. I do not modify the image by rotating or flipping. All 4 PNGs, when re-saved, have exactly the same size.
In addition, I have taken the 2.6MB PNG, opened it in Photoshop and saved two copies of it, one interlaced (reduced to 2.06MB), one non-interlaced (reduced to 1.7MB.) I then took each of those, ran them through your code and saved them. The resulting sizes of both were back to the original 2.6MB.
So, my guess is that the original images were created with a piece of software (like photoshop) and that piece of software has an optimized compression algorithm it is using for the PNG spec that .NET does not employ.
I've messed around with the EncoderParameter for Compression, but it seems to have no impact.