I'm saving some A4 images and smaller images to file.
I want to know what is the best format. They come back from a scan that is grayscale only. However some of the images are quite large in size (compared to what we would expect).
We have tried saving them as JPEG with different qualites but still can't get them as small as we'd like, is JPEG not the most effecient format for this.
A4 Saved at quality 8 is saving as 196KB smaller image saved at quality 8 is saving as 28KB
Because so much of this image is white space we expected much smaller file sizes. File size is more important here than image quality. Are we doing something wrong?
Here is sample A4 Image
Here is sample smaller Image
Our code is written in c#
// Get a bitmap.
Bitmap bmp1 = new Bitmap(@"c:\TestImageFromScanner.jpg");
ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
// Create an Encoder object based on the GUID
// for the Quality parameter category.
System.Drawing.Imaging.Encoder myEncoder =
System.Drawing.Imaging.Encoder.Quality;
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
// objects. In this case, there is only one
// EncoderParameter object in the array.
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder,8L);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(@"c:\TestJpegQuality8.jpg", jgpEncoder, myEncoderParameters);
But is there a best image format for images that are grayscale and mostly whitespace?
Looking at your image it's monochrome, not grayscale. And if monochrome is acceptable, you can use JBIG2 to compress your documents.
It has particular optimisations for text (among other things):
Ideally, a JBIG2 encoder will segment the input page into regions of text, regions of halftone images, and regions of other data. Regions which are neither text nor halftones are typically compressed using a context-dependent arithmetic coding algorithm called the QM coder. Textual regions are compressed as follows: the foreground pixels in the regions are grouped into symbols. A dictionary of symbols is then created and encoded, typically also using context-dependent arithmetic coding, and the regions are encoded by describing which symbols appear where.
Emphasis mine.
For images with large blocks of flat color, consider using PNG-8.
However, ta.speot.ls's suggestion in this case looks like it would meet your needs better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With