public void AxisParallelEllipsesWithDifferentRatio <TPixel>( TestImageProvider <TPixel> provider, float ratio) where TPixel : unmanaged, IPixel <TPixel> { Color yellow = Color.Yellow; Color red = Color.Red; Color black = Color.Black; provider.VerifyOperation( TolerantComparer, image => { var unicolorLinearGradientBrush = new EllipticGradientBrush( new Point(image.Width / 2, image.Height / 2), new Point(image.Width / 2, image.Width * 2 / 3), ratio, GradientRepetitionMode.None, new ColorStop(0, yellow), new ColorStop(1, red), new ColorStop(1, black)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, $"{ratio:F2}", false, false); }
public void WithEqualColorsReturnsUnicolorImage <TPixel>( TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { Color red = Color.Red; using (Image <TPixel> image = provider.GetImage()) { var unicolorLinearGradientBrush = new EllipticGradientBrush( new Point(0, 0), new Point(10, 0), 1.0f, GradientRepetitionMode.None, new ColorStop(0, red), new ColorStop(1, red)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); // no need for reference image in this test: image.ComparePixelBufferTo(red); } }
public void AxisParallelEllipsesWithDifferentRatio <TPixel>( TestImageProvider <TPixel> provider, float ratio) where TPixel : struct, IPixel <TPixel> { TPixel yellow = NamedColors <TPixel> .Yellow; TPixel red = NamedColors <TPixel> .Red; TPixel black = NamedColors <TPixel> .Black; provider.VerifyOperation( TolerantComparer, image => { var unicolorLinearGradientBrush = new EllipticGradientBrush <TPixel>( new SixLabors.Primitives.Point(image.Width / 2, image.Height / 2), new SixLabors.Primitives.Point(image.Width / 2, (image.Width * 2) / 3), ratio, GradientRepetitionMode.None, new ColorStop <TPixel>(0, yellow), new ColorStop <TPixel>(1, red), new ColorStop <TPixel>(1, black)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, $"{ratio:F2}", false, false); }
public override IBrush GetBrush() { IBrush brush = base.GetBrush(); RectangleF bounds = Bounds; if (bounds.IsEmpty || bounds.Width == 0 || bounds.Height == 0) { return(brush); } ColorStop[] colorStops = new ColorStop[Colors.Length]; for (int i = 0; i < Colors.Length; i++) { colorStops[i] = new ColorStop(Positions[i], Colors[i]); } switch (GradientType) { case GradientType.Circular: { float radius = bounds.Width / 2; Point center = new Point((int)(bounds.X + bounds.Width / 2), (int)(bounds.Y + bounds.Height / 2)); brush = new RadialGradientBrush(center, radius, GradientRepetitionMode.None, colorStops); } break; //case GradientType.Contour: // break; case GradientType.Linear: Point start = new Point((int)bounds.X, (int)(bounds.Y - bounds.Height / 2)); Point end = new Point((int)(bounds.X + bounds.Width), (int)(bounds.Y - bounds.Height / 2)); brush = new LinearGradientBrush(start, end, GradientRepetitionMode.None, colorStops); break; case GradientType.Rectangular: { Point center = new Point((int)(bounds.X + bounds.Width / 2), (int)(bounds.Y + bounds.Height / 2)); Point referenceAxisEnd = new Point((int)bounds.X, center.Y); float axisRatio = bounds.Width / bounds.Height; brush = new EllipticGradientBrush(center, referenceAxisEnd, axisRatio, GradientRepetitionMode.None, colorStops); } break; } return(brush); }
public void RotatedEllipsesWithDifferentRatio <TPixel>( TestImageProvider <TPixel> provider, float ratio, float rotationInDegree) where TPixel : unmanaged, IPixel <TPixel> { FormattableString variant = $"{ratio:F2}_AT_{rotationInDegree:00}deg"; provider.VerifyOperation( TolerantComparer, image => { Color yellow = Color.Yellow; Color red = Color.Red; Color black = Color.Black; var center = new Point(image.Width / 2, image.Height / 2); double rotation = Math.PI * rotationInDegree / 180.0; double cos = Math.Cos(rotation); double sin = Math.Sin(rotation); int offsetY = image.Height / 6; int axisX = center.X + (int)-(offsetY * sin); int axisY = center.Y + (int)(offsetY * cos); var unicolorLinearGradientBrush = new EllipticGradientBrush( center, new Point(axisX, axisY), ratio, GradientRepetitionMode.None, new ColorStop(0, yellow), new ColorStop(1, red), new ColorStop(1, black)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); }, variant, false, false); }