mirror of https://github.com/SixLabors/ImageSharp
2 changed files with 46 additions and 47 deletions
@ -0,0 +1,46 @@ |
|||||
|
// <copyright file="BackgroundColorTest.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageSharp.Tests.Processing.Effects |
||||
|
{ |
||||
|
using ImageSharp.PixelFormats; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
public class BackgroundColorTest : FileTestBase |
||||
|
{ |
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(DefaultFiles), StandardPixelType)] |
||||
|
public void ImageShouldApplyBackgroundColorFilter<TPixel>(TestImageProvider<TPixel> provider) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> image = provider.GetImage()) |
||||
|
{ |
||||
|
image.BackgroundColor(NamedColors<TPixel>.HotPink) |
||||
|
.DebugSave(provider, null, Extensions.Bmp); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[WithFileCollection(nameof(DefaultFiles), StandardPixelType)] |
||||
|
public void ImageShouldApplyBackgroundColorFilterInBox<TPixel>(TestImageProvider<TPixel> provider) |
||||
|
where TPixel : struct, IPixel<TPixel> |
||||
|
{ |
||||
|
using (Image<TPixel> source = provider.GetImage()) |
||||
|
using (var image = new Image<TPixel>(source)) |
||||
|
{ |
||||
|
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); |
||||
|
|
||||
|
image.BackgroundColor(NamedColors<TPixel>.HotPink, bounds) |
||||
|
.DebugSave(provider, null, Extensions.Bmp); |
||||
|
|
||||
|
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
|
||||
|
image.Fill(NamedColors<TPixel>.HotPink, bounds); |
||||
|
source.Fill(NamedColors<TPixel>.HotPink, bounds); |
||||
|
ImageComparer.CheckSimilarity(image, source); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,47 +0,0 @@ |
|||||
// <copyright file="BackgroundColorTest.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
namespace ImageSharp.Tests |
|
||||
{ |
|
||||
using System.IO; |
|
||||
|
|
||||
using ImageSharp.PixelFormats; |
|
||||
|
|
||||
using Xunit; |
|
||||
|
|
||||
public class BackgroundColorTest : FileTestBase |
|
||||
{ |
|
||||
[Fact] |
|
||||
public void ImageShouldApplyBackgroundColorFilter() |
|
||||
{ |
|
||||
string path = this.CreateOutputDirectory("BackgroundColor"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) |
|
||||
{ |
|
||||
image.BackgroundColor(Rgba32.HotPink).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void ImageShouldApplyBackgroundColorFilterInBox() |
|
||||
{ |
|
||||
string path = this.CreateOutputDirectory("BackgroundColor"); |
|
||||
|
|
||||
foreach (TestFile file in Files) |
|
||||
{ |
|
||||
string filename = file.GetFileName("-InBox"); |
|
||||
using (Image<Rgba32> image = file.CreateImage()) |
|
||||
using (FileStream output = File.OpenWrite($"{path}/{filename}")) |
|
||||
{ |
|
||||
image.BackgroundColor(Rgba32.HotPink, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue