|
|
|
@ -1,7 +1,5 @@ |
|
|
|
// <copyright file="Crop.cs" company="James Jackson-South">
|
|
|
|
// Copyright (c) James Jackson-South and contributors.
|
|
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
using System.Drawing; |
|
|
|
using System.Drawing.Drawing2D; |
|
|
|
@ -13,34 +11,28 @@ using SixLabors.ImageSharp.Processing.Processors.Text; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Benchmarks |
|
|
|
{ |
|
|
|
|
|
|
|
[MemoryDiagnoser] |
|
|
|
public class DrawTextOutline : BenchmarkBase |
|
|
|
{ |
|
|
|
|
|
|
|
[Params(10, 100)] |
|
|
|
public int TextIterations { get; set; } |
|
|
|
public string TextPhrase { get; set; } = "Hello World"; |
|
|
|
public string TextToRender => string.Join(" ", Enumerable.Repeat(TextPhrase, TextIterations)); |
|
|
|
|
|
|
|
|
|
|
|
[Benchmark(Baseline = true, Description = "System.Drawing Draw Text Outline")] |
|
|
|
public void DrawTextSystemDrawing() |
|
|
|
{ |
|
|
|
using (Bitmap destination = new Bitmap(800, 800)) |
|
|
|
using (var destination = new Bitmap(800, 800)) |
|
|
|
using (var graphics = Graphics.FromImage(destination)) |
|
|
|
{ |
|
|
|
|
|
|
|
using (Graphics graphics = Graphics.FromImage(destination)) |
|
|
|
graphics.InterpolationMode = InterpolationMode.Default; |
|
|
|
graphics.SmoothingMode = SmoothingMode.AntiAlias; |
|
|
|
using (var pen = new Pen(Color.HotPink, 10)) |
|
|
|
using (var font = new Font("Arial", 12, GraphicsUnit.Point)) |
|
|
|
using (var gp = new GraphicsPath()) |
|
|
|
{ |
|
|
|
graphics.InterpolationMode = InterpolationMode.Default; |
|
|
|
graphics.SmoothingMode = SmoothingMode.AntiAlias; |
|
|
|
using (var pen = new Pen(System.Drawing.Color.HotPink, 10)) |
|
|
|
using (var font = new Font("Arial", 12, GraphicsUnit.Point)) |
|
|
|
using (var gp = new GraphicsPath()) |
|
|
|
{ |
|
|
|
gp.AddString(TextToRender, font.FontFamily, (int)font.Style, font.Size, new RectangleF(10, 10, 780, 780), new StringFormat()); |
|
|
|
graphics.DrawPath(pen, gp); |
|
|
|
} |
|
|
|
gp.AddString(TextToRender, font.FontFamily, (int)font.Style, font.Size, new RectangleF(10, 10, 780, 780), new StringFormat()); |
|
|
|
graphics.DrawPath(pen, gp); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -48,7 +40,7 @@ namespace SixLabors.ImageSharp.Benchmarks |
|
|
|
[Benchmark(Description = "ImageSharp Draw Text Outline - Cached Glyphs")] |
|
|
|
public void DrawTextCore() |
|
|
|
{ |
|
|
|
using (Image<Rgba32> image = new Image<Rgba32>(800, 800)) |
|
|
|
using (var image = new Image<Rgba32>(800, 800)) |
|
|
|
{ |
|
|
|
var font = SixLabors.Fonts.SystemFonts.CreateFont("Arial", 12); |
|
|
|
image.Mutate(x => x.ApplyProcessor(new DrawTextProcessor<Rgba32>(new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, null, Processing.Pens.Solid(Rgba32.HotPink, 10), new SixLabors.Primitives.PointF(10, 10)))); |
|
|
|
@ -58,7 +50,7 @@ namespace SixLabors.ImageSharp.Benchmarks |
|
|
|
[Benchmark(Description = "ImageSharp Draw Text Outline - Nieve")] |
|
|
|
public void DrawTextCoreOld() |
|
|
|
{ |
|
|
|
using (Image<Rgba32> image = new Image<Rgba32>(800, 800)) |
|
|
|
using (var image = new Image<Rgba32>(800, 800)) |
|
|
|
{ |
|
|
|
var font = SixLabors.Fonts.SystemFonts.CreateFont("Arial", 12); |
|
|
|
image.Mutate(x => DrawTextOldVersion(x, new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, null, Processing.Pens.Solid(Rgba32.HotPink, 10), new SixLabors.Primitives.PointF(10, 10))); |
|
|
|
|