public static void Generate(string text, Font font) { using (Image <Rgba32> img = new Image <Rgba32>(1000, 1000)) { img.Mutate(x => x.Fill(Rgba32.White)); SixLabors.Primitives.RectangleF box = TextMeasurer.MeasureBounds(text, new RendererOptions(font)); (SixLabors.Shapes.IPathCollection paths, SixLabors.Shapes.IPathCollection boxes, SixLabors.Shapes.IPath textBox) = TextBuilder.GenerateGlyphsWithBox(text, new RendererOptions(font)); Rgba32 f = Rgba32.Fuchsia; f.A = 128; img.Mutate(x => x.Fill(Rgba32.Black, paths) .Draw(f, 1, boxes) .Draw(Rgba32.Lime, 1, new SixLabors.Shapes.RectangularPolygon(box))); img.Save("Output/Boxed.png"); } }
private void DrawRectangle(CognitiveResult face, string imgPath) { int x0 = face.faceRectangle.left; int y0 = face.faceRectangle.top; int width = face.faceRectangle.width; int height = face.faceRectangle.height; SixLabors.Primitives.RectangleF recc = new SixLabors.Primitives.RectangleF(x0, y0, width, height); float thick = 4; using (Image <Rgba32> image = Image.Load(imgPath)) { image.Mutate(DrawRectangleExtensions => DrawRectangleExtensions.Draw( color: boxColor, thickness: thick, shape: recc ) ); image.Save("tmpFace.jpg"); // Automatic encoder selected based on extension. } }
public static Image <Rgba32> GetDifferenceImage(Image <Rgba32> expected, byte[,] differences) { var differenceImage = expected.Clone(); IBrush <Rgba32> brush = Brushes.Percent20(Rgba32.Magenta); for (var y = 0; y < differences.GetLength(1); y++) { for (var x = 0; x < differences.GetLength(0); x++) { var cellValue = differences[x, y]; if (cellValue > 0) { var cellRectangle = new RectangleF((float)x * CellSize, (float)y * CellSize, CellSize, CellSize); differenceImage.Mutate(i => i.Fill(new GraphicsOptions(), brush, cellRectangle)); } } } return(differenceImage); }