Encapsulates methods to change the resolution of the image.
Inheritance: IGraphicsProcessor
Ejemplo n.º 1
0
        /// <summary>
        /// Sets the resolution of the image.
        /// <remarks>
        /// This method sets both the bitmap data and EXIF resolution if available.
        /// </remarks>
        /// </summary>
        /// <param name="horizontal">The horizontal resolution.</param>
        /// <param name="vertical">The vertical resolution.</param>
        /// <param name="unit">
        /// The unit of measure for the horizontal resolution and the vertical resolution. 
        /// Defaults to inches
        /// </param>
        /// <returns>
        /// The <see cref="ImageFactory"/>.
        /// </returns>
        public ImageFactory Resolution(int horizontal, int vertical, PropertyTagResolutionUnit unit = PropertyTagResolutionUnit.Inch)
        {
            if (this.ShouldProcess)
            {
                // Sanitize the input.
                horizontal = ImageMaths.Clamp(horizontal, 0, int.MaxValue);
                vertical = ImageMaths.Clamp(vertical, 0, int.MaxValue);

                Tuple<int, int, PropertyTagResolutionUnit> resolution =
                    new Tuple<int, int, PropertyTagResolutionUnit>(horizontal, vertical, unit);

                Resolution dpi = new Resolution { DynamicParameter = resolution };
                this.CurrentImageFormat.ApplyProcessor(dpi.ProcessImage, this);
            }

            return this;
        }
        /// <summary>
        /// Sets the resolution of the image.
        /// <remarks>
        /// This method sets both the bitmap data and EXIF resolution if available.
        /// </remarks>
        /// </summary>
        /// <param name="horizontal">The horizontal resolution.</param>
        /// <param name="vertical">The vertical resolution.</param>
        /// <param name="unit">
        /// The unit of measure for the horizontal resolution and the vertical resolution. 
        /// Defaults to inches
        /// </param>
        /// <returns>
        /// The <see cref="ImageFactory"/>.
        /// </returns>
        public ImageFactory Resolution(int horizontal, int vertical, PropertyTagResolutionUnit unit = PropertyTagResolutionUnit.Inch)
        {
            if (this.ShouldProcess)
            {
                // Sanitize the input.
                if (horizontal < 0 || vertical < 0)
                {
                    return this;
                }

                Tuple<int, int, PropertyTagResolutionUnit> resolution =
                    new Tuple<int, int, PropertyTagResolutionUnit>(horizontal, vertical, unit);

                Resolution dpi = new Resolution { DynamicParameter = resolution };
                this.backupFormat.ApplyProcessor(dpi.ProcessImage, this);
            }

            return this;
        }