|
| 1 | +using SixLabors.Fonts; |
| 2 | +using SixLabors.ImageSharp.Drawing.Processing; |
| 3 | +using SixLabors.ImageSharp.PixelFormats; |
| 4 | +using SixLabors.ImageSharp.Processing; |
| 5 | +using Xunit; |
| 6 | + |
| 7 | +namespace SixLabors.ImageSharp.Drawing.Tests.Issues |
| 8 | +{ |
| 9 | + public class Issue_54 |
| 10 | + { |
| 11 | + [Fact] |
| 12 | + public void CanDrawWithoutMemoryException() |
| 13 | + { |
| 14 | + int width = 768; |
| 15 | + int height = 438; |
| 16 | + |
| 17 | + // Creates a new image with empty pixel data. |
| 18 | + using (var image = new Image<Rgba32>(width, height)) |
| 19 | + { |
| 20 | + { |
| 21 | + FontCollection collection = new FontCollection(); |
| 22 | + FontFamily family = collection.Install(@"C:\Windows\Fonts\verdana.ttf"); |
| 23 | + Font font = family.CreateFont(48, FontStyle.Bold); |
| 24 | + |
| 25 | + // The options are optional |
| 26 | + TextGraphicsOptions options = new TextGraphicsOptions() |
| 27 | + { |
| 28 | + TextOptions = new TextOptions() |
| 29 | + { |
| 30 | + ApplyKerning = true, |
| 31 | + TabWidth = 8, // a tab renders as 8 spaces wide |
| 32 | + WrapTextWidth = width, // greater than zero so we will word wrap at 100 pixels wide |
| 33 | + HorizontalAlignment = HorizontalAlignment.Center // right align |
| 34 | + } |
| 35 | + }; |
| 36 | + |
| 37 | + IBrush brush = Brushes.Solid(Color.White); |
| 38 | + //IPen pen = Pens.DashDot(Color.White, 0); //0 makes application freeze and eat memory |
| 39 | + IPen pen = Pens.Solid(Color.White, 0); //0 makes application crash |
| 40 | + string text = "sample text"; |
| 41 | + |
| 42 | + // Draw the text |
| 43 | + image.Mutate(x => x.DrawText(options, text, font, brush, pen, new PointF(0, 100))); |
| 44 | + } |
| 45 | + |
| 46 | + } // Dispose - releasing memory into a memory pool ready for the next image you wish to process. |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments