Using Six Labors ImageSharp 1.0.4 for .Net core, how can I draw a line between two points? My code below combines three images into the GridImage
and then I want to draw a line on the new image.
When I call imageContext.DrawLines(linePen, points)
I am getting the error:
The type IImageProcessingContext<> is defined in a reference that is not referenced to assembly Sixlabors.ImageSharp.
However, I am referencing SixLabors in the using statement.
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using System;
using System.IO;
public void CombineImagesDrawLine() {
using (Image<Rgba32> img1 = Image.Load<Rgba32>("gridTemplate.png"))
using (Image<Rgba32> img2 = Image.Load<Rgba32>("circleOne.png"))
using (Image<Rgba32> img3 = Image.Load<Rgba32>("circleTwo.png"))
using (Image<Rgba32> GridImage = new Image<Rgba32>(1024, 576)) // create output image of the correct dimensions
{
// take img1 and img2 and draw them onto the image
GridImage.Mutate(o => o
.DrawImage(img1, new Point(0, 0), 1f)
.DrawImage(img2, new Point(100, 100), 1f)
);
// Add img3
GridImage.Mutate(o => o
.DrawImage(img3, new Point(200, 250), 1f)
);
GridImage.Mutate(imageContext =>
{
var points = new SixLabors.Primitives.PointF[2];
points[0] = new SixLabors.Primitives.PointF(
x: (float)(89),
y: (float)(118));
points[1] = new SixLabors.Primitives.PointF(
x: (float)(901),
y: (float)(379));
var lineColor = SixLabors.ImageSharp.Color.FromRgb(
r: (byte)124,
g: (byte)190,
b: (byte)75);
float lineWidth = 5;
var linePen = new Pen(lineColor, lineWidth);
imageContext.DrawLines(linePen, points); // !!This is where my code fails
}
}