Menu ▾ ▴

#33 jpeg quality should be tunable

2.X
closed
nobody
None
Feature Request
Medium
N/A
2015-08-04
2015-05-11
No

This is a quick fix. The quality argument must be long to be applied well.

        private static MemoryStream EncodeBitmap(Bitmap bitmap, ImageFormat imageFormat)
        {
            var encoded = new MemoryStream();
            if (imageFormat == ImageFormat.Jpeg)
            {
                var encoder = ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == ImageFormat.Jpeg.Guid);
                var encParams = new EncoderParameters() { Param = new[] { new EncoderParameter(Encoder.Quality, 85L) } };
                bitmap.Save(encoded, encoder, encParams);
            }
            else
            {
                bitmap.Save(encoded, imageFormat);
            }
            return encoded;
        }

Discussion


Log in to post a comment.