Bitmap clip = new Bitmap((int)(8.5 * 72), (int)(11 * 72));
MemoryStream stream = new MemoryStream();
clip.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
byte[] bytes = stream.ToArray();
I ran it on my machine and the bytes.Length was 8587, on my fellow developers' machines it was 2009. Supposedly in .NET there's no way to influence the quality (or rather the ratio in this case) of the PNG compression. This particular image is a blank one, and I have other tests which work with images with content and they confirm that the compression is lossless (I encountered some debates where that was a question).
But even if the compression is lossless, there's is a tradeoff between the compression algorithm runtime + CPU utilization vs the compression ratio / quality. I wonder how System.Drawing.Imaging determines the quality, because this above case clearly shows that there can be differences. How can I be sure that on the client's machine it won't choose 100% quality (which would yield a 1.457.337 size file)?
Related material:
- PNG Compression in .net
- C# - How to change PNG quality or color depth
- save png image with custom quality or color depth in C#
- http://bytes.com/topic/c-sharp/answers/700494-how-specify-compression-level-when-saving-loseless-pngs
Additional info:
- Checked out another developer's machine and it's consistent with my other colleagues results, so my machine is the outlier.
- Each machine has Win 7 Prof 64 bit installed on it, the particular tests are NUnit and we are using .NET 4
- Can any of my installed software override the behavior of .NET in this respect. For example I have IrfanView installed, can it replace any system wide "filters" or dlls used? (BTW I checked in the Modules debug view and I don't see any unusual dll loaded)
- Can it influenced by some windows OS desktop quality settings or something?