I thought GDI+ was supposed to be good. I am sure that it is better than whatever came before, but as far as I can tell its JPEG encoding is poor. Consider the following code, which creates a BMP format file from a System.Drawing.Image:
System.Drawing.Image myImage = thumbnail( afileName ); //makes the image
ImageCodecInfo myImageCodecInfo;
myImageCodecInfo = GetEncoderInfo( "image/bmp" );//bmp so uncompressed
EncoderParameters eps = new EncoderParameters(1);
eps.Param[0] = new EncoderParameter( Encoder.Quality, 100L );//don't really use this as bmp
myImage.Save( ( thisDir + "admin\\zip\\" + thumbName ), myImageCodecInfo, eps );
The following code uses GDI+ to produce a JPEG file of the same image, at “100%” Quality.
System.Drawing.Image myImage = thumbnail( afileName ); //makes the image
ImageCodecInfo myImageCodecInfo;
myImageCodecInfo = GetEncoderInfo( “image/jpeg” );//jpg so compressed
EncoderParameters eps = new EncoderParameters(1);
eps.Param[0] = new EncoderParameter( Encoder.Quality, 100L );//this is 100% quality!
myImage.Save( ( thisDir + “admin\\zip\\” + thumbName ), myImageCodecInfo, eps );
GDI+ BMP Image | GDI+ JPEG 100% | Photoshop JPEG 80% |
The problem with my example above is that the browser renders them quite similarly. It is still easy to tell that the middle one is of the poorest quality, but the difference is not so pronounced. Download the images and view them in your favourite viewer, or compare these 400% zooms of a portion of the BMP and JPEG images:
GDI+ BMP | GDI+ JPEG |
That is NOT 100% Quality, in my book.
So the call is going out to all the real developers out there. What am I doing wrong? Is there a better way? Comments please.
Hi mate,
From what I know 100% quality of JPEG produces artifacts (as you can well see). I believe the recomandation is 80 or 85 for best results.
Good luck
The image errors that you see are due to JPEG “subsampling”. This is normally applied independently of JPEG “quality”.
JPEG at quality 100 can be nearly lossless if you can figure out how to turn off the subsampling.
Maybe this is accomplished by the LuminanceTable and ChrominanceTable parameters (I can’t find it documented).