pamela fluente wrote:
[...]
to save JPG with some give given quality. I expected to do the same
with PNG. I know its a loseless format, but I expect to be able to
control the compression level. Is that right or no ?
My PNG are ways too big (relative to similar jpg's).
You should not expect to be able to control the compression level in the
way that you are doing.
PNG does support a variety of parameters for controlling how the
compression is done. But different parameters will result in better
results for different input images.
JPEG's compression level is essentially a control over how much
information to throw away. Higher quality discards less information,
lower quality discards more. The more information you throw out, the
smaller the file. .NET provides a simple 0 to 100 parameter to control
how much information is discarded.
PNG's parameters (assuming you have an implementation that provides
access to them) control varying ways that the algorithm can deal with
the input data. A given set of parameters will not always produce the
smallest files; for a given input image, the smallest file is obtained
with a specific set of parameters, but a different input image may
require a different set of parameters.
The only way to optimize (make the smallest) the output of PNG
compression is to try a wide variety of parameters and pick the best
results. This means compressing the image multiple times, and depending
on how optimal you want to get, the number of times could be very large.
You should not, in any case, expect the size of a PNG-compressed file to
approximate the size of a JPEG-compressed file. The two algorithms
serve very different purposes, and aren't really comparable. JPEG
throws out data, which makes it a lot easier to get very small files.
But because it throws out data, it works best with images for which you
won't notice the loss of data, like photographs or elaborate drawings.
For basic images, like bitmaps with text or simple drawings, compressing
using JPEG can produce very unlikable results. The image will have
"artifacts" all over it, causing clean lines to get blurry or distorted.
On the other hand, for simple images like this, PNG's compression,
even a default mode, can often do a pretty good job.
Whether it can do a better job than JPEG depends a lot on the input data
and how you are using each compression technique. But generally
speaking, JPEG isn't going to provide anywhere near the equivalent
quality for simple images like those PNG is well-suited for, especially
when it's used in a way that produces a file significantly smaller than PNG.
Now, all that said...as far as I know, .NET's support for PNG offers
basically no options for controlling the parameters for PNG. So you
don't really have a choice, if you're going to use .NET's PNG support.
There are other options though.
Here's a command-line utility that does allow for control of various
parameters:
http://advsys.net/ken/util/pngout.htm
Here's a .NET program that uses that tool, but via a GUI:
http://brh.numbera.com/software/pnggauntlet/
Here's a web site full of useful information about PNG:
http://www.libpng.org/pub/png/
Here's that web site's introduction of PNG to beginners:
http://www.libpng.org/pub/png/pngintro.html
Hope that helps.
Pete