public IEncoder CreateIfSuitable(ResizeSettings settings, object original) { ImageFormat requestedFormat = DefaultEncoder.GetRequestedFormat(settings.Format, ImageFormat.Jpeg); if (requestedFormat == null || !IsValidOutputFormat(requestedFormat)) { return(null); //An unsupported format was explicitly specified. } if (!"wic".Equals(settings["encoder"], StringComparison.OrdinalIgnoreCase)) { return(null); } return(new WicEncoderPlugin(settings, original)); }
public ImageFormat GetFormatIfSuitable(ResizeSettings settings, object original) { //What format was the image originally (used as a fallback). ImageFormat originalFormat = DefaultEncoder.GetOriginalFormat(original); if (!IsValidOutputFormat(originalFormat)) { originalFormat = null; //No valid info available about the original format. } //What format was specified? ImageFormat requestedFormat = DefaultEncoder.GetRequestedFormat(settings.Format, originalFormat); //fallback to originalFormat if not specified. if (IsValidOutputFormat(requestedFormat)) { return(requestedFormat); } return(null); }
public FreeImageEncoderPlugin(ResizeSettings settings, object original) { ImageFormat originalFormat = DefaultEncoder.GetOriginalFormat(original); if (!IsValidOutputFormat(originalFormat)) { originalFormat = ImageFormat.Jpeg; //No valid info available about the original format. Use Jpeg. } //What format was specified? ImageFormat requestedFormat = DefaultEncoder.GetRequestedFormat(settings.Format, originalFormat); //fallback to originalFormat if not specified. if (!IsValidOutputFormat(requestedFormat)) { throw new ArgumentException("An unrecognized or unsupported output format (" + (settings.Format != null ? settings.Format : "(null)") + ") was specified in 'settings'."); } this.format = FreeImage.GetFormat(requestedFormat); //Parse JPEG settings. int quality = 90; if (string.IsNullOrEmpty(settings["quality"]) || !int.TryParse(settings["quality"], NumberStyles.Number, NumberFormatInfo.InvariantInfo, out quality)) { quality = 90; } if (format == FREE_IMAGE_FORMAT.FIF_JPEG) { if (quality >= 100) { encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB; } else if (quality >= 75) { encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD; } else if (quality >= 50) { encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYNORMAL; } else if (quality >= 25) { encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYAVERAGE; } else { encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYBAD; } if ("true".Equals(settings["progressive"])) { encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_PROGRESSIVE; } if ("411".Equals(settings["subsampling"])) { encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_411; } if ("420".Equals(settings["subsampling"])) { encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_420; } if ("422".Equals(settings["subsampling"])) { encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_422; } if ("444".Equals(settings["subsampling"])) { encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_444; } } if (string.IsNullOrEmpty(settings["colors"]) || !int.TryParse(settings["colors"], NumberStyles.Number, NumberFormatInfo.InvariantInfo, out colors)) { colors = -1; } if (format == FREE_IMAGE_FORMAT.FIF_GIF) { //encodingOptions = FREE_IMAGE_SAVE_FLAGS. } }