/
BackgroundColorExtensions.cs
67 lines (61 loc) · 2.98 KB
/
BackgroundColorExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Processing.Processors.Overlays;
namespace SixLabors.ImageSharp.Processing;
/// <summary>
/// Defines extension methods to replace the background color of an <see cref="Image"/>
/// using Mutate/Clone.
/// </summary>
public static class BackgroundColorExtensions
{
/// <summary>
/// Replaces the background color of image with the given one.
/// </summary>
/// <param name="source">The current image processing context.</param>
/// <param name="color">The color to set as the background.</param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, Color color) =>
BackgroundColor(source, source.GetGraphicsOptions(), color);
/// <summary>
/// Replaces the background color of image with the given one.
/// </summary>
/// <param name="source">The current image processing context.</param>
/// <param name="color">The color to set as the background.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext BackgroundColor(
this IImageProcessingContext source,
Color color,
Rectangle rectangle) =>
BackgroundColor(source, source.GetGraphicsOptions(), color, rectangle);
/// <summary>
/// Replaces the background color of image with the given one.
/// </summary>
/// <param name="source">The current image processing context.</param>
/// <param name="options">The options effecting pixel blending.</param>
/// <param name="color">The color to set as the background.</param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext BackgroundColor(
this IImageProcessingContext source,
GraphicsOptions options,
Color color) =>
source.ApplyProcessor(new BackgroundColorProcessor(options, color));
/// <summary>
/// Replaces the background color of image with the given one.
/// </summary>
/// <param name="source">The current image processing context.</param>
/// <param name="options">The options effecting pixel blending.</param>
/// <param name="color">The color to set as the background.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/>.</returns>
public static IImageProcessingContext BackgroundColor(
this IImageProcessingContext source,
GraphicsOptions options,
Color color,
Rectangle rectangle) =>
source.ApplyProcessor(new BackgroundColorProcessor(options, color), rectangle);
}