// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing { /// /// Adds extensions that allow the drawing of images to the type. /// public static class DrawImageExtensions { /// /// 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 opacity of the image to blend. Must be between 0 and 1. /// The . public static IImageProcessingContext DrawImage( this IImageProcessingContext source, Image image, float opacity) { var options = new GraphicsOptions(); return source.ApplyProcessor( new DrawImageProcessor( image, Point.Empty, options.ColorBlendingMode, options.AlphaCompositionMode, opacity)); } /// /// 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 blending mode. /// The opacity of the image to blend. Must be between 0 and 1. /// The . public static IImageProcessingContext DrawImage( this IImageProcessingContext source, Image image, PixelColorBlendingMode colorBlending, float opacity) => source.ApplyProcessor( new DrawImageProcessor( image, Point.Empty, colorBlending, new GraphicsOptions().AlphaCompositionMode, opacity)); /// /// 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 color blending mode. /// The alpha composition mode. /// The opacity of the image to blend. Must be between 0 and 1. /// The . public static IImageProcessingContext DrawImage( this IImageProcessingContext source, Image image, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity) => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, colorBlending, alphaComposition, opacity)); /// /// 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 options, including the blending type and blending amount. /// The . public static IImageProcessingContext DrawImage( this IImageProcessingContext source, Image image, GraphicsOptions options) => source.ApplyProcessor( new DrawImageProcessor( image, Point.Empty, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage)); /// /// 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 location to draw the blended image. /// The opacity of the image to blend. Must be between 0 and 1. /// The . public static IImageProcessingContext DrawImage( this IImageProcessingContext source, Image image, Point location, float opacity) { var options = new GraphicsOptions(); return source.ApplyProcessor( new DrawImageProcessor( image, location, options.ColorBlendingMode, options.AlphaCompositionMode, opacity)); } /// /// 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 location to draw the blended image. /// The color blending to apply. /// The opacity of the image to blend. Must be between 0 and 1. /// The . public static IImageProcessingContext DrawImage( this IImageProcessingContext source, Image image, Point location, PixelColorBlendingMode colorBlending, float opacity) => source.ApplyProcessor( new DrawImageProcessor( image, location, colorBlending, new GraphicsOptions().AlphaCompositionMode, opacity)); /// /// 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 location to draw the blended image. /// The color blending to apply. /// The alpha composition mode. /// The opacity of the image to blend. Must be between 0 and 1. /// The . public static IImageProcessingContext DrawImage( this IImageProcessingContext source, Image image, Point location, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity) => source.ApplyProcessor(new DrawImageProcessor(image, location, colorBlending, alphaComposition, opacity)); /// /// 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 location to draw the blended image. /// The options containing the blend mode and opacity. /// The . public static IImageProcessingContext DrawImage( this IImageProcessingContext source, Image image, Point location, GraphicsOptions options) => source.ApplyProcessor( new DrawImageProcessor( image, location, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage)); } }