// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
{
///
/// 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 location to draw the blended image.
/// The options.
/// The .
public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, GraphicsOptions options)
where TPixel : struct, IPixel
{
source.ApplyProcessor(new DrawImageProcessor(image, location, options));
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 to blend. Must be between 0 and 1.
/// The .
public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, float opacity)
where TPixel : struct, IPixel
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlendPercentage = opacity;
return DrawImage(source, image, Point.Empty, 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 to blend. Must be between 0 and 1.
/// The .
public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float opacity)
where TPixel : struct, IPixel
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlendPercentage = opacity;
options.BlenderMode = blender;
return DrawImage(source, image, Point.Empty, 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 blending amount.
/// The .
public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, GraphicsOptions options)
where TPixel : struct, IPixel
{
return DrawImage(source, image, Point.Empty, 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 to blend. Must be between 0 and 1.
/// The location to draw the blended image.
/// The .
public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, float opacity, Point location)
where TPixel : struct, IPixel
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlendPercentage = opacity;
return source.DrawImage(image, 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 to blend. Must be between 0 and 1.
/// The location to draw the blended image.
/// The .
public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float opacity, Point location)
where TPixel : struct, IPixel
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlenderMode = blender;
options.BlendPercentage = opacity;
return source.DrawImage(image, location, options);
}
}
}