|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using SixLabors.ImageSharp.ColorSpaces; |
| 6 | +using SixLabors.ImageSharp.Drawing.Processing; |
| 7 | +using SixLabors.ImageSharp.PixelFormats; |
| 8 | +using SixLabors.ImageSharp.Processing; |
| 9 | +using Xunit; |
| 10 | + |
| 11 | +namespace SixLabors.ImageSharp.Drawing.Tests.Issues |
| 12 | +{ |
| 13 | + public class Issue_28 |
| 14 | + { |
| 15 | + private Rgba32 red = Color.Red.ToRgba32(); |
| 16 | + |
| 17 | + [Fact] |
| 18 | + public void DrawingLineAtTopShouldDisplay() |
| 19 | + { |
| 20 | + using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black); |
| 21 | + image.Mutate(x => x |
| 22 | + .SetGraphicsOptions(g => g.Antialias = false) |
| 23 | + .DrawLines( |
| 24 | + this.red, |
| 25 | + 1f, |
| 26 | + new PointF(0, 0), |
| 27 | + new PointF(100, 0) |
| 28 | + )); |
| 29 | + |
| 30 | + var locations = Enumerable.Range(0, 100).Select(i => (x: i, y: 0)); |
| 31 | + Assert.All(locations, l => |
| 32 | + { |
| 33 | + Assert.Equal(this.red, image[l.x, l.y]); |
| 34 | + }); |
| 35 | + } |
| 36 | + |
| 37 | + [Fact] |
| 38 | + public void DrawingLineAtBottomShouldDisplay() |
| 39 | + { |
| 40 | + using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black); |
| 41 | + image.Mutate(x => x |
| 42 | + .SetGraphicsOptions(g => g.Antialias = false) |
| 43 | + .DrawLines( |
| 44 | + this.red, |
| 45 | + 1f, |
| 46 | + new PointF(0, 99), |
| 47 | + new PointF(100, 99) |
| 48 | + )); |
| 49 | + |
| 50 | + var locations = Enumerable.Range(0, 100).Select(i => (x: i, y: 99)); |
| 51 | + Assert.All(locations, l => |
| 52 | + { |
| 53 | + Assert.Equal(this.red, image[l.x, l.y]); |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | + [Fact] |
| 58 | + public void DrawingLineAtLeftShouldDisplay() |
| 59 | + { |
| 60 | + using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black); |
| 61 | + image.Mutate(x => x |
| 62 | + .SetGraphicsOptions(g => g.Antialias = false) |
| 63 | + .DrawLines( |
| 64 | + this.red, |
| 65 | + 1f, |
| 66 | + new PointF(0, 0), |
| 67 | + new PointF(0, 99) |
| 68 | + )); |
| 69 | + |
| 70 | + var locations = Enumerable.Range(0, 100).Select(i => (x: 0, y: i)); |
| 71 | + Assert.All(locations, l => |
| 72 | + { |
| 73 | + Assert.Equal(this.red, image[l.x, l.y]); |
| 74 | + }); |
| 75 | + } |
| 76 | + |
| 77 | + [Fact] |
| 78 | + public void DrawingLineAtRightShouldDisplay() |
| 79 | + { |
| 80 | + using var image = new Image<Rgba32>(Configuration.Default, 100, 100, Color.Black); |
| 81 | + image.Mutate(x => x |
| 82 | + .SetGraphicsOptions(g => g.Antialias = false) |
| 83 | + .DrawLines( |
| 84 | + this.red, |
| 85 | + 1f, |
| 86 | + new PointF(99, 0), |
| 87 | + new PointF(99, 99) |
| 88 | + )); |
| 89 | + |
| 90 | + var locations = Enumerable.Range(0, 100).Select(i => (x: 99, y: i)); |
| 91 | + Assert.All(locations, l => |
| 92 | + { |
| 93 | + Assert.Equal(this.red, image[l.x, l.y]); |
| 94 | + }); |
| 95 | + } |
| 96 | + |
| 97 | + //public void DrawWithSystemDrawing() |
| 98 | + //{ |
| 99 | + // GraphicsPath p = new GraphicsPath(); |
| 100 | + // p.AddString( |
| 101 | + // "My Text String", // text to draw |
| 102 | + // FontFamily.GenericSansSerif, // or any other font family |
| 103 | + // (int)FontStyle.Regular, // font style (bold, italic, etc.) |
| 104 | + // g.DpiY * fontSize / 72, // em size |
| 105 | + // new Point(0, 0), // location where to draw text |
| 106 | + // new StringFormat()); // set options here (e.g. center alignment) |
| 107 | + // g.DrawPath(Pens.Black, p); |
| 108 | + //} |
| 109 | + } |
| 110 | +} |
0 commit comments