mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.4 KiB
102 lines
3.4 KiB
// <copyright file="ColorConversionTests.cs" company="James Jackson-South">
|
|
// Copyright (c) James Jackson-South and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
// </copyright>
|
|
|
|
namespace ImageSharp.Tests.Drawing
|
|
{
|
|
using ShapePath = SixLabors.Shapes.Path;
|
|
using SixLabors.Shapes;
|
|
using System.IO;
|
|
using System.Numerics;
|
|
|
|
using ImageSharp.PixelFormats;
|
|
|
|
using Xunit;
|
|
|
|
public class DrawPathTests : FileTestBase
|
|
{
|
|
[Fact]
|
|
public void ImageShouldBeOverlayedByPath()
|
|
{
|
|
string path = this.CreateOutputDirectory("Drawing", "Path");
|
|
using (Image image = new Image(500, 500))
|
|
{
|
|
LinearLineSegment linerSegemnt = new LinearLineSegment(
|
|
new Vector2(10, 10),
|
|
new Vector2(200, 150),
|
|
new Vector2(50, 300));
|
|
BezierLineSegment bazierSegment = new BezierLineSegment(new Vector2(50, 300),
|
|
new Vector2(500, 500),
|
|
new Vector2(60, 10),
|
|
new Vector2(10, 400));
|
|
|
|
ShapePath p = new ShapePath(linerSegemnt, bazierSegment);
|
|
|
|
using (FileStream output = File.OpenWrite($"{path}/Simple.png"))
|
|
{
|
|
image
|
|
.BackgroundColor(Rgba32.Blue)
|
|
.Draw(Rgba32.HotPink, 5, p)
|
|
.Save(output);
|
|
}
|
|
|
|
using (PixelAccessor<Rgba32> sourcePixels = image.Lock())
|
|
{
|
|
Assert.Equal(Rgba32.HotPink, sourcePixels[9, 9]);
|
|
|
|
Assert.Equal(Rgba32.HotPink, sourcePixels[199, 149]);
|
|
|
|
Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
public void ImageShouldBeOverlayedPathWithOpacity()
|
|
{
|
|
string path = this.CreateOutputDirectory("Drawing", "Path");
|
|
|
|
Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);
|
|
|
|
|
|
LinearLineSegment linerSegemnt = new LinearLineSegment(
|
|
new Vector2(10, 10),
|
|
new Vector2(200, 150),
|
|
new Vector2(50, 300)
|
|
);
|
|
|
|
BezierLineSegment bazierSegment = new BezierLineSegment(new Vector2(50, 300),
|
|
new Vector2(500, 500),
|
|
new Vector2(60, 10),
|
|
new Vector2(10, 400));
|
|
|
|
ShapePath p = new ShapePath(linerSegemnt, bazierSegment);
|
|
|
|
using (Image image = new Image(500, 500))
|
|
{
|
|
using (FileStream output = File.OpenWrite($"{path}/Opacity.png"))
|
|
{
|
|
image
|
|
.BackgroundColor(Rgba32.Blue)
|
|
.Draw(color, 10, p)
|
|
.Save(output);
|
|
}
|
|
|
|
//shift background color towards forground color by the opacity amount
|
|
Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f));
|
|
|
|
using (PixelAccessor<Rgba32> sourcePixels = image.Lock())
|
|
{
|
|
Assert.Equal(mergedColor, sourcePixels[9, 9]);
|
|
|
|
Assert.Equal(mergedColor, sourcePixels[199, 149]);
|
|
|
|
Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|