/// <summary> /// Flips an image by the given instructions. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image to rotate, flip, or both.</param> /// <param name="flipType">The <see cref="FlipType"/> to perform the flip.</param> /// <returns>The <see cref="Image"/></returns> public static Image <TColor> Flip <TColor>(this Image <TColor> source, FlipType flipType) where TColor : struct, IPackedPixel, IEquatable <TColor> { FlipProcessor <TColor> processor = new FlipProcessor <TColor>(flipType); return(source.Apply(source.Bounds, processor)); }
/// <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)); }
/// <summary> /// Resizes an image to the given width and height with the given sampler and /// source rectangle. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image to resize.</param> /// <param name="width">The target image width.</param> /// <param name="height">The target image height.</param> /// <param name="sampler">The <see cref="IResampler"/> to perform the resampling.</param> /// <param name="sourceRectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw. /// </param> /// <param name="targetRectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the target image object to draw to. /// </param> /// <param name="compand">Whether to compress and expand the image color-space to gamma correct the image during processing.</param> /// <returns>The <see cref="Image{TColor}"/></returns> /// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks> public static Image <TColor> Resize <TColor>(this Image <TColor> source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand = false) where TColor : struct, IPackedPixel, IEquatable <TColor> { if (width == 0 && height > 0) { width = source.Width * height / source.Height; targetRectangle.Width = width; } if (height == 0 && width > 0) { height = source.Height * width / source.Width; targetRectangle.Height = height; } Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); ResamplingWeightedProcessor <TColor> processor; if (compand) { processor = new CompandingResizeProcessor <TColor>(sampler, width, height, targetRectangle); } else { processor = new ResizeProcessor <TColor>(sampler, width, height, targetRectangle); } return(source.Apply(sourceRectangle, processor)); }
/// <summary> /// Crops an image to the area of greatest entropy. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image to crop.</param> /// <param name="threshold">The threshold for entropic density.</param> /// <returns>The <see cref="Image"/></returns> public static Image <TColor> EntropyCrop <TColor>(this Image <TColor> source, float threshold = .5f) where TColor : struct, IPackedPixel, IEquatable <TColor> { EntropyCropProcessor <TColor> processor = new EntropyCropProcessor <TColor>(threshold); return(source.Apply(source.Bounds, processor)); }
/// <summary> /// Skews an image by the given angles in degrees. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image to skew.</param> /// <param name="degreesX">The angle in degrees to perform the rotation along the x-axis.</param> /// <param name="degreesY">The angle in degrees to perform the rotation along the y-axis.</param> /// <param name="expand">Whether to expand the image to fit the skewed result.</param> /// <returns>The <see cref="Image"/></returns> public static Image <TColor> Skew <TColor>(this Image <TColor> source, float degreesX, float degreesY, bool expand) where TColor : struct, IPackedPixel, IEquatable <TColor> { SkewProcessor <TColor> processor = new SkewProcessor <TColor> { AngleX = degreesX, AngleY = degreesY, Expand = expand }; return(source.Apply(source.Bounds, processor)); }
/// <summary> /// Applies Grayscale toning to the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <param name="mode">The formula to apply to perform the operation.</param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> Grayscale <TColor>(this Image <TColor> source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709) where TColor : struct, IPackedPixel, IEquatable <TColor> { IImageProcessor <TColor> processor = mode == GrayscaleMode.Bt709 ? (IImageProcessor <TColor>) new GrayscaleBt709Processor <TColor>() : new GrayscaleBt601Processor <TColor>(); return(source.Apply(rectangle, processor)); }
/// <summary> /// Rotates an image by the given angle in degrees. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image to rotate.</param> /// <param name="degrees">The angle in degrees to perform the rotation.</param> /// <param name="expand">Whether to expand the image to fit the rotated result.</param> /// <returns>The <see cref="Image"/></returns> public static Image <TColor> Rotate <TColor>(this Image <TColor> source, float degrees, bool expand) where TColor : struct, IPackedPixel, IEquatable <TColor> { RotateProcessor <TColor> processor = new RotateProcessor <TColor> { Angle = degrees, Expand = expand }; return(source.Apply(source.Bounds, processor)); }
/// <summary> /// Pixelates an image with the given pixel size. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="size">The size of the pixels.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> Pixelate <TColor>(this Image <TColor> source, int size, Rectangle rectangle) where TColor : struct, IPackedPixel, IEquatable <TColor> { if (size <= 0 || size > source.Height || size > source.Width) { throw new ArgumentOutOfRangeException(nameof(size)); } return(source.Apply(rectangle, new PixelateProcessor <TColor>(size))); }
/// <summary> /// Alters the colors of the image recreating an oil painting effect. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="levels">The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image.</param> /// <param name="brushSize">The number of neighboring pixels used in calculating each individual pixel value.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> OilPaint <TColor>(this Image <TColor> source, int levels, int brushSize, Rectangle rectangle) where TColor : struct, IPackedPixel, IEquatable <TColor> { Guard.MustBeGreaterThan(levels, 0, nameof(levels)); if (brushSize <= 0 || brushSize > source.Height || brushSize > source.Width) { throw new ArgumentOutOfRangeException(nameof(brushSize)); } return(source.Apply(rectangle, new OilPaintingProcessor <TColor>(levels, brushSize))); }
/// <summary> /// Applies a radial glow effect to an image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="color">The color to set as the glow.</param> /// <param name="radius">The the radius.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> Glow <TColor>(this Image <TColor> source, TColor color, float radius, Rectangle rectangle) where TColor : struct, IPackedPixel, IEquatable <TColor> { GlowProcessor <TColor> processor = new GlowProcessor <TColor> { Radius = radius, }; if (!color.Equals(default(TColor))) { processor.GlowColor = color; } return(source.Apply(rectangle, processor)); }
/// <summary> /// Applies a radial vignette effect to an image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="color">The color to set as the vignette.</param> /// <param name="radiusX">The the x-radius.</param> /// <param name="radiusY">The the y-radius.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> Vignette <TColor>(this Image <TColor> source, TColor color, float radiusX, float radiusY, Rectangle rectangle) where TColor : struct, IPackedPixel, IEquatable <TColor> { VignetteProcessor <TColor> processor = new VignetteProcessor <TColor> { RadiusX = radiusX, RadiusY = radiusY }; if (!color.Equals(default(TColor))) { processor.VignetteColor = color; } return(source.Apply(rectangle, processor)); }
/// <summary> /// Draws the given image together with the current one by blending their pixels. /// </summary> /// <param name="source">The image this method extends.</param> /// <param name="image">The image to blend with the currently processing image.</param> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param> /// <param name="size">The size to draw the blended image.</param> /// <param name="location">The location to draw the blended image.</param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> DrawImage <TColor>(this Image <TColor> source, Image <TColor> image, int percent, Size size, Point location) where TColor : struct, IPackedPixel, IEquatable <TColor> { if (size == default(Size)) { size = new Size(image.Width, image.Height); } if (location == default(Point)) { location = Point.Empty; } return(source.Apply(source.Bounds, new DrawImageProcessor <TColor>(image, size, location, percent))); }
/// <summary> /// Applies the given colorblindness simulator to the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="colorBlindness">The type of color blindness simulator to apply.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> ColorBlindness <TColor>(this Image <TColor> source, ColorBlindness colorBlindness, Rectangle rectangle) where TColor : struct, IPackedPixel, IEquatable <TColor> { IImageProcessor <TColor> processor; switch (colorBlindness) { case ImageSharp.Processing.ColorBlindness.Achromatomaly: processor = new AchromatomalyProcessor <TColor>(); break; case ImageSharp.Processing.ColorBlindness.Achromatopsia: processor = new AchromatopsiaProcessor <TColor>(); break; case ImageSharp.Processing.ColorBlindness.Deuteranomaly: processor = new DeuteranomalyProcessor <TColor>(); break; case ImageSharp.Processing.ColorBlindness.Deuteranopia: processor = new DeuteranopiaProcessor <TColor>(); break; case ImageSharp.Processing.ColorBlindness.Protanomaly: processor = new ProtanomalyProcessor <TColor>(); break; case ImageSharp.Processing.ColorBlindness.Protanopia: processor = new ProtanopiaProcessor <TColor>(); break; case ImageSharp.Processing.ColorBlindness.Tritanomaly: processor = new TritanomalyProcessor <TColor>(); break; default: processor = new TritanopiaProcessor <TColor>(); break; } return(source.Apply(rectangle, processor)); }
/// <summary> /// Alters the contrast component of the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="amount">The new contrast of the image. Must be between -100 and 100.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> Contrast <TColor>(this Image <TColor> source, int amount, Rectangle rectangle) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(rectangle, new ContrastProcessor <TColor>(amount))); }
/// <summary> /// Detects any edges within the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <param name="filter">The filter for detecting edges.</param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> DetectEdges <TColor>(this Image <TColor> source, Rectangle rectangle, IEdgeDetectorProcessor <TColor> filter) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(rectangle, filter)); }
/// <summary> /// Alters the alpha component of the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="percent">The new opacity of the image. Must be between 0 and 100.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="Image"/>.</returns> public static Image <TColor> Alpha <TColor>(this Image <TColor> source, int percent, Rectangle rectangle) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(rectangle, new AlphaProcessor <TColor>(percent))); }
/// <summary> /// Draws the path with the provided pen. /// </summary> /// <typeparam name="TColor">The type of the color.</typeparam> /// <param name="source">The source.</param> /// <param name="pen">The pen.</param> /// <param name="path">The path.</param> /// <returns>The Image</returns> public static Image <TColor> DrawPath <TColor>(this Image <TColor> source, IPen <TColor> pen, IPath path) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(new DrawPathProcessor <TColor>(pen, path, GraphicsOptions.Default))); }
/// <summary> /// Flood fills the image in the shape of the provided polygon with the specified brush.. /// </summary> /// <typeparam name="TColor">The type of the color.</typeparam> /// <param name="source">The source.</param> /// <param name="brush">The brush.</param> /// <param name="shape">The shape.</param> /// <returns>The Image</returns> public static Image <TColor> Fill <TColor>(this Image <TColor> source, IBrush <TColor> brush, RectangleF shape) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(new FillShapeProcessor <TColor>(brush, new RectangularPolygon(shape), GraphicsOptions.Default))); }
/// <summary> /// Applies a box blur to the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="radius">The 'radius' value representing the size of the area to sample.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> BoxBlur <TColor>(this Image <TColor> source, int radius, Rectangle rectangle) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(rectangle, new BoxBlurProcessor <TColor>(radius))); }
/// <summary> /// Flood fills the image with the specified brush. /// </summary> /// <typeparam name="TColor">The type of the color.</typeparam> /// <param name="source">The source.</param> /// <param name="brush">The brush.</param> /// <returns>The Image</returns> public static Image <TColor> Fill <TColor>(this Image <TColor> source, IBrush <TColor> brush) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(new FillProcessor <TColor>(brush))); }
/// <summary> /// Flood fills the image in the shape o fhte provided polygon with the specified brush.. /// </summary> /// <typeparam name="TColor">The type of the color.</typeparam> /// <param name="source">The source.</param> /// <param name="brush">The brush.</param> /// <param name="shape">The shape.</param> /// <param name="options">The graphics options.</param> /// <returns>The Image</returns> public static Image <TColor> Fill <TColor>(this Image <TColor> source, IBrush <TColor> brush, IShape shape, GraphicsOptions options) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(new FillShapeProcessor <TColor>(brush, shape, options))); }
/// <summary> /// Applies binarization to the image splitting the pixels at the given threshold. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> BinaryThreshold <TColor>(this Image <TColor> source, float threshold, Rectangle rectangle) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(rectangle, new BinaryThresholdProcessor <TColor>(threshold))); }
/// <summary> /// Applies a Gaussian blur to the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="sigma">The 'sigma' value representing the weight of the blur.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> GaussianBlur <TColor>(this Image <TColor> source, float sigma, Rectangle rectangle) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(rectangle, new GaussianBlurProcessor <TColor>(sigma))); }
/// <summary> /// Flood fills the image with the specified brush. /// </summary> /// <typeparam name="TPixel">The type of the color.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="brush">The details how to fill the region of interest.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static Image <TPixel> Fill <TPixel>(this Image <TPixel> source, IBrush <TPixel> brush) where TPixel : struct, IPixel <TPixel> { return(source.Apply(new FillProcessor <TPixel>(brush))); }
/// <summary> /// Draws the outline of the region with the provided pen. /// </summary> /// <typeparam name="TColor">The type of the color.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="pen">The pen.</param> /// <param name="path">The path.</param> /// <param name="options">The options.</param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> Draw <TColor>(this Image <TColor> source, IPen <TColor> pen, Drawable path, GraphicsOptions options) where TColor : struct, IPixel <TColor> { return(source.Apply(new DrawPathProcessor <TColor>(pen, path, options))); }
/// <summary> /// Alters the hue component of the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="degrees">The angle in degrees to adjust the image.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> Hue <TColor>(this Image <TColor> source, float degrees, Rectangle rectangle) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(rectangle, new HueProcessor <TColor>(degrees))); }
/// <summary> /// Flood fills the image with in the region with the specified brush. /// </summary> /// <typeparam name="TPixel">The type of the color.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="brush">The brush.</param> /// <param name="region">The region.</param> /// <param name="options">The graphics options.</param> /// <returns>The <see cref="Image{TPixel}"/>.</returns> public static Image <TPixel> Fill <TPixel>(this Image <TPixel> source, IBrush <TPixel> brush, Region region, GraphicsOptions options) where TPixel : struct, IPixel <TPixel> { return(source.Apply(new FillRegionProcessor <TPixel>(brush, region, options))); }
/// <summary> /// Draws the outline of the polygon with the provided pen. /// </summary> /// <typeparam name="TColor">The type of the color.</typeparam> /// <param name="source">The source.</param> /// <param name="pen">The pen.</param> /// <param name="shape">The shape.</param> /// <param name="options">The options.</param> /// <returns> /// The Image /// </returns> public static Image <TColor> DrawPolygon <TColor>(this Image <TColor> source, IPen <TColor> pen, RectangleF shape, GraphicsOptions options) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(new DrawPathProcessor <TColor>(pen, (IPath) new RectangularPolygon(shape), options))); }
/// <summary> /// Inverts the colors of the image. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="rectangle"> /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// </param> /// <returns>The <see cref="Image"/>.</returns> public static Image <TColor> Invert <TColor>(this Image <TColor> source, Rectangle rectangle) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(rectangle, new InvertProcessor <TColor>())); }
/// <summary> /// Replaces the background color of image with the given one. /// </summary> /// <typeparam name="TColor">The pixel format.</typeparam> /// <param name="source">The image this method extends.</param> /// <param name="color">The color to set as the background.</param> /// <returns>The <see cref="Image{TColor}"/>.</returns> public static Image <TColor> BackgroundColor <TColor>(this Image <TColor> source, TColor color) where TColor : struct, IPackedPixel, IEquatable <TColor> { return(source.Apply(source.Bounds, new BackgroundColorProcessor <TColor>(color))); }