Example #1
0
        public void CropWidthHeightCropProcessorWithRectangleSet(int width, int height)
        {
            this.operations.Crop(width, height);
            CropProcessor processor = this.Verify <CropProcessor>();

            Assert.Equal(new Rectangle(0, 0, width, height), processor.CropRectangle);
        }
Example #2
0
        /// <summary>
        /// Crops an image to the given rectangle.
        /// </summary>
        /// <typeparam name="TColor">The pixel format.</typeparam>
        /// <param name="source">The image to crop.</param>
        /// <param name="cropRectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to retain.
        /// </param>
        /// <returns>The <see cref="Image"/></returns>
        public static Image <TColor> Crop <TColor>(this Image <TColor> source, Rectangle cropRectangle)
            where TColor : struct, IPackedPixel, IEquatable <TColor>
        {
            CropProcessor <TColor> processor = new CropProcessor <TColor>(cropRectangle);

            return(source.Apply(source.Bounds, processor));
        }
Example #3
0
        /// <summary>
        /// Crops an image to the given width and height with the given source rectangle.
        /// <remarks>
        /// If the source rectangle is smaller than the target dimensions then the
        /// area within the source is resized performing a zoomed crop.
        /// </remarks>
        /// </summary>
        /// <typeparam name="T">The pixel format.</typeparam>
        /// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
        /// <param name="source">The image to crop.</param>
        /// <param name="width">The target image width.</param>
        /// <param name="height">The target image height.</param>
        /// <param name="sourceRectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
        /// </param>
        /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
        /// <returns>The <see cref="Image"/></returns>
        public static Image <T, TP> Crop <T, TP>(this Image <T, TP> source, int width, int height, Rectangle sourceRectangle, ProgressEventHandler progressHandler = null)
            where T : IPackedVector <TP>
            where TP : struct
        {
            Guard.MustBeGreaterThan(width, 0, nameof(width));
            Guard.MustBeGreaterThan(height, 0, nameof(height));

            if (sourceRectangle.Width < width || sourceRectangle.Height < height)
            {
                // If the source rectangle is smaller than the target perform a
                // cropped zoom.
                source = source.Resize(sourceRectangle.Width, sourceRectangle.Height);
            }

            CropProcessor <T, TP> processor = new CropProcessor <T, TP>();

            processor.OnProgress += progressHandler;

            try
            {
                return(source.Process(width, height, sourceRectangle, new Rectangle(0, 0, width, height), processor));
            }
            finally
            {
                processor.OnProgress -= progressHandler;
            }
        }
        /// <summary>
        /// Crops an image to the given rectangle.
        /// </summary>
        /// <typeparam name="TColor">The pixel format.</typeparam>
        /// <param name="source">The image to crop.</param>
        /// <param name="cropRectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to retain.
        /// </param>
        /// <returns>The <see cref="Image"/></returns>
        public static Image <TColor> Crop <TColor>(this Image <TColor> source, Rectangle cropRectangle)
            where TColor : struct, IPixel <TColor>
        {
            CropProcessor <TColor> processor = new CropProcessor <TColor>(cropRectangle);

            source.ApplyProcessor(processor, source.Bounds);
            return(source);
        }
Example #5
0
        /// <summary>
        /// Crops an image to the given rectangle.
        /// </summary>
        /// <typeparam name="TColor">The pixel format.</typeparam>
        /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
        /// <param name="source">The image to crop.</param>
        /// <param name="cropRectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to retain.
        /// </param>
        /// <returns>The <see cref="Image"/></returns>
        public static Image <TColor, TPacked> Crop <TColor, TPacked>(this Image <TColor, TPacked> source, Rectangle cropRectangle)
            where TColor : struct, IPackedPixel <TPacked>
            where TPacked : struct, IEquatable <TPacked>
        {
            CropProcessor <TColor, TPacked> processor = new CropProcessor <TColor, TPacked>(cropRectangle);

            return(source.Process(source.Bounds, processor));
        }
Example #6
0
        public void CropRectangleCropProcessorWithRectangleSet(int x, int y, int width, int height)
        {
            var cropRectangle = new Rectangle(x, y, width, height);

            this.operations.Crop(cropRectangle);
            CropProcessor processor = this.Verify <CropProcessor>();

            Assert.Equal(cropRectangle, processor.CropRectangle);
        }
Example #7
0
        /// <summary>
        /// Crops an image to the given width and height with the given source rectangle.
        /// <remarks>
        /// If the source rectangle is smaller than the target dimensions then the
        /// area within the source is resized performing a zoomed crop.
        /// </remarks>
        /// </summary>
        /// <typeparam name="TColor">The pixel format.</typeparam>
        /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
        /// <param name="source">The image to crop.</param>
        /// <param name="width">The target image width.</param>
        /// <param name="height">The target image height.</param>
        /// <param name="sourceRectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
        /// </param>
        /// <returns>The <see cref="Image"/></returns>
        public static Image <TColor, TPacked> Crop <TColor, TPacked>(this Image <TColor, TPacked> source, int width, int height, Rectangle sourceRectangle)
            where TColor : struct, IPackedPixel <TPacked>
            where TPacked : struct
        {
            Guard.MustBeGreaterThan(width, 0, nameof(width));
            Guard.MustBeGreaterThan(height, 0, nameof(height));

            if (sourceRectangle.Width < width || sourceRectangle.Height < height)
            {
                // If the source rectangle is smaller than the target perform a
                // cropped zoom.
                source = source.Resize(sourceRectangle.Width, sourceRectangle.Height);
            }

            CropProcessor <TColor, TPacked> processor = new CropProcessor <TColor, TPacked>();

            return(source.Process(width, height, sourceRectangle, new Rectangle(0, 0, width, height), processor));
        }