/// <summary>
        /// Encodes the image to the specified stream from the <see cref="Image{TColor}"/>.
        /// </summary>
        /// <typeparam name="TColor">The pixel format.</typeparam>
        /// <param name="image">The <see cref="Image{TColor}"/> to encode from.</param>
        /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
        /// <param name="options">The options for the encoder.</param>
        public void Encode <TColor>(Image <TColor> image, Stream stream, IJpegEncoderOptions options)
            where TColor : struct, IPixel <TColor>
        {
            JpegEncoderCore encode = new JpegEncoderCore(options);

            encode.Encode(image, stream);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="image">The <see cref="Image{TPixel}"/> to encode from.</param>
        /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
        public void Encode <TPixel>(Image <TPixel> image, Stream stream)
            where TPixel : struct, IPixel <TPixel>
        {
            var encoder = new JpegEncoderCore(this);

            encoder.Encode(image, stream);
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public void Encode <TColor, TPacked>(Image <TColor, TPacked> image, Stream stream)
            where TColor : struct, IPackedPixel <TPacked>
            where TPacked : struct
        {
            JpegEncoderCore encode = new JpegEncoderCore();

            if (this.subsampleSet)
            {
                encode.Encode(image, stream, this.Quality, this.Subsample);
            }
            else
            {
                encode.Encode(image, stream, this.Quality, this.Quality >= 80 ? JpegSubsample.Ratio444 : JpegSubsample.Ratio420);
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public void Encode <TColor>(Image <TColor> image, Stream stream)
            where TColor : struct, IPackedPixel, IEquatable <TColor>
        {
            JpegEncoderCore encode = new JpegEncoderCore();

            if (this.subsampleSet)
            {
                encode.Encode(image, stream, this.Quality, this.Subsample);
            }
            else
            {
                // Match Photoshop and use 4:2:0 SUpsampling at quality < 51%
                encode.Encode(image, stream, this.Quality, this.Quality >= 51 ? JpegSubsample.Ratio444 : JpegSubsample.Ratio420);
            }
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        public void Encode <TColor>(Image <TColor> image, Stream stream)
            where TColor : struct, IPackedPixel, IEquatable <TColor>
        {
            // Ensure that quality can be set but has a fallback.
            if (image.MetaData.Quality > 0)
            {
                this.Quality = image.MetaData.Quality;
            }

            JpegEncoderCore encode = new JpegEncoderCore();

            if (this.subsampleSet)
            {
                encode.Encode(image, stream, this.Quality, this.Subsample);
            }
            else
            {
                // Use 4:2:0 Subsampling at quality < 91% for reduced filesize.
                encode.Encode(image, stream, this.Quality, this.Quality >= 91 ? JpegSubsample.Ratio444 : JpegSubsample.Ratio420);
            }
        }