/// <summary> /// Performs compression on the specified stream. With some formats the image will be decoded /// and encoded and this will result in a small quality reduction. If the new size is not /// smaller the stream won't be overwritten. /// </summary> /// <param name="stream">The stream of the image to compress.</param> /// <returns>True when the image could be compressed otherwise false.</returns> public bool Compress(Stream stream) { ImageOptimizerHelper.CheckStream(stream); var optimizer = GetOptimizer(stream); if (optimizer == null) { return(false); } optimizer.OptimalCompression = OptimalCompression; return(optimizer.Compress(stream)); }
/// <summary> /// Performs lossless compression on the specified stream. If the new stream size is not smaller /// the stream won't be overwritten. /// </summary> /// <param name="stream">The stream of the image to compress.</param> /// <returns>True when the image could be compressed otherwise false.</returns> public bool LosslessCompress([ValidatedNotNull] Stream stream) { ImageOptimizerHelper.CheckStream(stream); var optimizer = GetOptimizer(stream); if (optimizer == null) { return(false); } optimizer.OptimalCompression = OptimalCompression; return(optimizer.LosslessCompress(stream)); }