/// <summary>
        /// Resizes the current image to the given dimensions using Content Aware Resizing.
        /// </summary>
        /// <param name="factory">
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class
        /// that this method extends.
        /// </param>
        /// <param name="layer">
        /// The <see cref="ContentAwareResizeLayer"/> containing the properties required to resize the image.
        /// </param>
        /// <returns>
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        public static ImageFactory ContentAwareResize(this ImageFactory factory, ContentAwareResizeLayer layer)
        {
            if (factory.ShouldProcess)
            {
                Dictionary<string, string> resizeSettings = new Dictionary<string, string> { { "MaxWidth", layer.Size.Width.ToString("G") }, { "MaxHeight", layer.Size.Height.ToString("G") } };

                ContentAwareResize resize = new ContentAwareResize { DynamicParameter = layer, Settings = resizeSettings };
                factory.CurrentImageFormat.ApplyProcessor(resize.ProcessImage, factory);
            }

            return factory;
        }
        /// <summary>
        /// Resizes the current image to the given dimensions using Content Aware Resizing.
        /// </summary>
        /// <param name="factory">
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class
        /// that this method extends.
        /// </param>
        /// <param name="size">
        /// The <see cref="T:System.Drawing.Size"/> containing the width and height to set the image to.
        /// </param>
        /// <returns>
        /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
        /// </returns>
        public static ImageFactory ContentAwareResize(this ImageFactory factory, Size size)
        {
            if (factory.ShouldProcess)
            {
                int width = size.Width;
                int height = size.Height;

                ContentAwareResizeLayer resizeLayer = new ContentAwareResizeLayer(new Size(width, height));
                return factory.ContentAwareResize(resizeLayer);
            }

            return factory;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a value that indicates whether the specified object is an
        /// <see cref="ContentAwareResizeLayer"/> object that is equivalent to
        /// this <see cref="ContentAwareResizeLayer"/> object.
        /// </summary>
        /// <param name="obj">
        /// The object to test.
        /// </param>
        /// <returns>
        /// True if the given object  is an <see cref="ContentAwareResizeLayer"/> object that is equivalent to
        /// this <see cref="ContentAwareResizeLayer"/> object; otherwise, false.
        /// </returns>
        public override bool Equals(object obj)
        {
            ContentAwareResizeLayer resizeLayer = obj as ContentAwareResizeLayer;

            if (resizeLayer == null)
            {
                return(false);
            }

            return(this.Size == resizeLayer.Size &&
                   this.ConvolutionType == resizeLayer.ConvolutionType &&
                   this.EnergyFunction == resizeLayer.EnergyFunction &&
                   this.OutputType == resizeLayer.OutputType &&
                   this.Parallelize == resizeLayer.Parallelize &&
                   this.Timeout == resizeLayer.Timeout &&
                   this.WeightPath == resizeLayer.WeightPath);
        }