Example #1
0
        /// <summary>
        /// Creates a cropped view of the source context.
        /// </summary>
        public static IReadOnlyPixelRows Crop(
            this IReadOnlyPixelRowsContext context, int x, int y)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(Crop(context, new Rectangle(x, y, context.Width - x, context.Height - y)));
        }
Example #2
0
        /// <summary>
        /// Creates a cropped view of the source context.
        /// </summary>
        public static IReadOnlyPixelRows Crop(
            this IReadOnlyPixelRowsContext context, Rectangle sourceRectangle)
        {
            if (CheckBounds(context, sourceRectangle))
            {
                return(context);
            }

            return(new ReadOnlyCropRows(context.Pixels, sourceRectangle));
        }
Example #3
0
        /// <summary>
        /// Creates a cropped view of the source context.
        /// </summary>
        public static IReadOnlyPixelRows <TPixel> Crop <TPixel>(
            this IReadOnlyPixelRowsContext <TPixel> context, int x, int y)
            where TPixel : unmanaged, IPixel
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(Crop(context, new Rectangle(x, y, context.Width - x, context.Height - y)));
        }
Example #4
0
        /// <summary>
        /// Creates a cropped view of the source context.
        /// </summary>
        public static IReadOnlyPixelRows <TPixel> Crop <TPixel>(
            this IReadOnlyPixelRowsContext <TPixel> context, Rectangle sourceRectangle)
            where TPixel : unmanaged, IPixel
        {
            if (CheckBounds(context, sourceRectangle))
            {
                return(context);
            }

            return(new ReadOnlyCropRows <TPixel>(context.Pixels, sourceRectangle));
        }
        internal static bool CheckBounds(this IReadOnlyPixelRowsContext context, Rectangle sourceRectangle)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.Pixels.GetBounds() == sourceRectangle)
            {
                return(true);
            }

            ImagingArgumentGuard.AssertRectangleInSource(context, sourceRectangle, nameof(sourceRectangle));
            return(false);
        }
Example #6
0
 /// <summary>
 /// Creates a cropped view of the source context.
 /// </summary>
 public static IReadOnlyPixelRows <TPixel> Crop <TPixel>(
     this IReadOnlyPixelRowsContext <TPixel> context, int x, int y, int width, int height)
     where TPixel : unmanaged, IPixel
 {
     return(Crop(context, new Rectangle(x, y, width, height)));
 }
Example #7
0
 /// <summary>
 /// Creates a cropped view of the source context.
 /// </summary>
 public static IReadOnlyPixelRows Crop(
     this IReadOnlyPixelRowsContext context, int x, int y, int width, int height)
 {
     return(Crop(context, new Rectangle(x, y, width, height)));
 }