private static Image TransformJpeg(Image image, EncoderValue transformationCode) { EncoderParameters encoderParams = new EncoderParameters(1); encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Transformation, (long)transformationCode); byte[] imageBytes = ImageTools.EncodeImageParams(image, ImageFormat.Jpeg, encoderParams); return(ImageFromByteArray(imageBytes)); }
// From SaveImageToFile, JpegCompress public static byte[] EncodeImage(Image image, ImageFormat destFormat, int quality = 80) { byte[] imageBytes; if ((destFormat == null) || (image.RawFormat.Equals(destFormat))) { imageBytes = ImageTools.ByteArrayFromImage(image); } else { EncoderParameters encoderParams = null; if (destFormat.Equals(ImageFormat.Jpeg)) { // quality is used by Jpeg and probably ignored by other formats encoderParams = new EncoderParameters(1); encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality); } imageBytes = ImageTools.EncodeImageParams(image, destFormat, encoderParams); } return(imageBytes); }