// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp { using System; using Drawing.Processors; using ImageSharp.Drawing; using ImageSharp.PixelFormats; /// /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Draws the given image together with the current one by blending their pixels. /// /// The image this method extends. /// The image to blend with the currently processing image. /// The pixel format. /// The size to draw the blended image. /// The location to draw the blended image. /// The options. /// The . public static Image DrawImage(this Image source, Image image, Size size, Point location, GraphicsOptions options) where TPixel : struct, IPixel { if (size == default(Size)) { size = new Size(image.Width, image.Height); } if (location == default(Point)) { location = Point.Empty; } source.ApplyProcessor(new DrawImageProcessor(image, size, location, options), source.Bounds); return source; } /// /// Draws the given image together with the current one by blending their pixels. /// /// The pixel format. /// The image this method extends. /// The image to blend with the currently processing image. /// The opacity of the image image to blend. Must be between 0 and 1. /// The . public static Image Blend(this Image source, Image image, float percent) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; options.BlendPercentage = percent; return DrawImage(source, image, default(Size), default(Point), options); } /// /// Draws the given image together with the current one by blending their pixels. /// /// The pixel format. /// The image this method extends. /// The image to blend with the currently processing image. /// The blending mode. /// The opacity of the image image to blend. Must be between 0 and 1. /// The . public static Image Blend(this Image source, Image image, PixelBlenderMode blender, float percent) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; options.BlendPercentage = percent; options.BlenderMode = blender; return DrawImage(source, image, default(Size), default(Point), options); } /// /// Draws the given image together with the current one by blending their pixels. /// /// The pixel format. /// The image this method extends. /// The image to blend with the currently processing image. /// The options, including the blending type and belnding amount. /// The . public static Image Blend(this Image source, Image image, GraphicsOptions options) where TPixel : struct, IPixel { return DrawImage(source, image, default(Size), default(Point), options); } /// /// Draws the given image together with the current one by blending their pixels. /// /// The image this method extends. /// The image to blend with the currently processing image. /// The pixel format. /// The opacity of the image image to blend. Must be between 0 and 1. /// The size to draw the blended image. /// The location to draw the blended image. /// The . public static Image DrawImage(this Image source, Image image, float percent, Size size, Point location) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; options.BlendPercentage = percent; return source.DrawImage(image, size, location, options); } /// /// Draws the given image together with the current one by blending their pixels. /// /// The image this method extends. /// The image to blend with the currently processing image. /// The pixel format. /// The type of bending to apply. /// The opacity of the image image to blend. Must be between 0 and 1. /// The size to draw the blended image. /// The location to draw the blended image. /// The . public static Image DrawImage(this Image source, Image image, PixelBlenderMode blender, float percent, Size size, Point location) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; options.BlenderMode = blender; options.BlendPercentage = percent; return source.DrawImage(image, size, location, options); } } }