foreach (ImageCodecInfo codec in codecs) { if (codec.FormatID == format.Guid) { return codec; } } returnnull; }
编码及压缩
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Bitmap target = new Bitmap(width, height);
// format and encoder // the format is used by the encoder // to generate ImageCodecInfo ImageFormat format = ImageFormat.Jpeg; ImageCodecInfo encoder = GetEncoder(format);
// Bitmap.Save takes the EncoderParameters, // but what we make is a EncoderParameter, no "s" at the end. // use EncoderParameters.Param[0] to assign EncoderParameters pm = new EncoderParameters(1); pm.Param[0] = new EncoderParameter(Encoder.Quality, 80L);