/// <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);
        }
        /// <inheritdoc/>
        public void Encode <TColor>(Image <TColor> image, Stream stream, IEncoderOptions options)
            where TColor : struct, IPixel <TColor>
        {
            IJpegEncoderOptions gifOptions = JpegEncoderOptions.Create(options);

            this.Encode(image, stream, gifOptions);
        }
示例#3
0
 public HomeController(IFileProvider fileProvider, IJpegEncoderOptions encoderOptions, IDistributedCache cache, ILogger <HomeController> logger)
 {
     _logger         = logger;
     _encoderOptions = encoderOptions;
     _fileProvider   = fileProvider;
     _cache          = cache;
 }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegEncoderCore"/> class.
        /// </summary>
        /// <param name="options">The options</param>
        public JpegEncoderCore(IJpegEncoderOptions options)
        {
            // System.Drawing produces identical output for jpegs with a quality parameter of 0 and 1.
            this.quality   = options.Quality.Clamp(1, 100);
            this.subsample = options.Subsample ?? (this.quality >= 91 ? JpegSubsample.Ratio444 : JpegSubsample.Ratio420);

            this.ignoreMetadata = options.IgnoreMetadata;
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegEncoderCore"/> class.
        /// </summary>
        /// <param name="options">The options.</param>
        public JpegEncoderCore(IJpegEncoderOptions options)
        {
            this.quality = options.Quality;

            if (IsSupportedColorType(options.ColorType))
            {
                this.colorType = options.ColorType;
            }
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegEncoderCore"/> class.
        /// </summary>
        /// <param name="options">The options</param>
        public JpegEncoderCore(IJpegEncoderOptions options)
        {
            int quality = options.Quality;

            if (quality == 0)
            {
                quality = 75;
            }

            this.quality   = quality;
            this.subsample = options.Subsample ?? (quality >= 91 ? JpegSubsample.Ratio444 : JpegSubsample.Ratio420);

            this.ignoreMetadata = options.IgnoreMetadata;
        }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JpegEncoderCore"/> class.
 /// </summary>
 /// <param name="options">The options</param>
 public JpegEncoderCore(IJpegEncoderOptions options)
 {
     this.quality   = options.Quality;
     this.subsample = options.Subsample;
 }
示例#8
0
 public HomeController(IHostingEnvironment env, IJpegEncoderOptions encoderOptions)
 {
     _encoderOptions = encoderOptions;
     _fileProvider   = env.WebRootFileProvider;
 }
示例#9
0
        /// <summary>
        /// Saves the image to the given stream with the jpeg format.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="source">The image this method extends.</param>
        /// <param name="stream">The stream to save the image to.</param>
        /// <param name="options">The options for the encoder.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
        /// <returns>
        /// The <see cref="Image{TPixel}"/>.
        /// </returns>
        public static Image <TPixel> SaveAsJpeg <TPixel>(this Image <TPixel> source, Stream stream, IJpegEncoderOptions options)
            where TPixel : struct, IPixel <TPixel>
        {
            JpegEncoder encoder = new JpegEncoder();

            encoder.Encode(source, stream, options);

            return(source);
        }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JpegEncoderCore"/> class.
 /// </summary>
 /// <param name="options">The options for the encoder.</param>
 public JpegEncoderCore(IJpegEncoderOptions options)
 {
     this.options = options ?? new JpegEncoderOptions();
 }