品質の指定は、Bitmap.Save() にエンコードパラメータを与えるだけ。
using System.Drawing.Imaging; private void ConvertJpeg() { // Loads JPEG image. Bitmap bmp1 = new Bitmap(@"C:\Test.jpg"); // Creates the encoder object. Encoder myEncoder = Encoder.Quality; // Creates the encode parameter (Quality=50) // Higher quality compresses image more. // Quality=100 applies the highest compression. EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 50L); EncoderParameters myEncoderParameters = new EncoderParameters(1); myEncoderParameters.Param[0] = myEncoderParameter; // Saves the bitmap. ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg); bmp1.Save(@"C:\TestResult.jpg", jgpEncoder, myEncoderParameters); } private ImageCodecInfo GetEncoder(ImageFormat format) { ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders(); foreach (ImageCodecInfo codec in codecs) { if (codec.FormatID == format.Guid) { return codec; } } return null; }
参考サイト
方法 : JPEG 圧縮レベルの設定
http://msdn.microsoft.com/ja-jp/library/bb882583(v=vs.110).aspx