/// <summary> /// Sets the encoder lossy quality. /// </summary> /// <param name="quality">The quality.</param> /// <exception cref="ArgumentOutOfRangeException">The quality parameter is not in the range of [0, 100] inclusive.</exception> /// <exception cref="HeifException">A LibHeif error occurred.</exception> /// <exception cref="ObjectDisposedException">The object has been disposed.</exception> public void SetLossyQuality(int quality) { if (quality < 0 || quality > 100) { ExceptionUtil.ThrowArgumentOutOfRangeException(nameof(quality), "Must be in the range of [0, 100]."); } VerifyNotDisposed(); var error = LibHeifNative.heif_encoder_set_lossy_quality(this.encoder, quality); error.ThrowIfError(); }
/// <summary> /// Sets the lossless compression support. /// </summary> /// <param name="lossless"> /// <see langword="true"/> if the encoder should use lossless compression; otherwise, <see langword="false"/>. /// </param> /// <exception cref="HeifException">A LibHeif error occurred.</exception> /// <exception cref="ObjectDisposedException">The object has been disposed.</exception> public void SetLossless(bool lossless) { VerifyNotDisposed(); var error = LibHeifNative.heif_encoder_set_lossless(this.encoder, lossless); error.ThrowIfError(); if (lossless && !this.lossyQualitySet) { // LibHeif requires the lossy quality to be always be set, if it has // not been set the encoder will produce a corrupted image. error = LibHeifNative.heif_encoder_set_lossy_quality(this.encoder, 50); error.ThrowIfError(); this.lossyQualitySet = true; } }