ImageSharp.Drawing icon indicating copy to clipboard operation
ImageSharp.Drawing copied to clipboard

drawText with PatternBrush ThrowArgumentOutOfRangeException

Open Computr1x opened this issue 3 years ago • 0 comments

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have verified that I am running the latest version of ImageSharp.Drawing
  • [x] I have verified if the problem exist in both DEBUG and RELEASE mode
  • [x] I have searched open and closed issues to ensure it has not already been reported

Description

Get a exception ThrowArgumentOutOfRangeException when try to draw text with PatternBrush (like Horizontal, Min, Percent10, etc.), but with Sold brush it's work fine.

Stacktrace:

 в System.ThrowHelper.ThrowArgumentOutOfRangeException()
   в SixLabors.ImageSharp.Drawing.Processing.PatternBrush.PatternBrushApplicator`1.Apply(Span`1 scanline, Int32 x, Int32 y)
   в SixLabors.ImageSharp.Drawing.Processing.Processors.Text.DrawTextProcessor`1.<OnFrameApply>g__Draw|5_0(List`1 operations, IBrush brush, <>c__DisplayClass5_0& )
   в SixLabors.ImageSharp.Drawing.Processing.Processors.Text.DrawTextProcessor`1.OnFrameApply(ImageFrame`1 source)
   в SixLabors.ImageSharp.Processing.Processors.ImageProcessor`1.SixLabors.ImageSharp.Processing.Processors.IImageProcessor<TPixel>.Execute()
   в SixLabors.ImageSharp.Processing.DefaultImageProcessorContext`1.ApplyProcessor(IImageProcessor processor, Rectangle rectangle)
   в SixLabors.ImageSharp.Processing.DefaultImageProcessorContext`1.ApplyProcessor(IImageProcessor processor)
   в Program.<>c__DisplayClass0_0.<<Main>$>b__3(IImageProcessingContext x) в D:\Coding\TestImageSharp\TestImageSharp\Program.cs:строка 32
   в SixLabors.ImageSharp.Processing.ProcessingExtensions.ProcessingVisitor.Visit[TPixel](Image`1 image)
   в Program.<Main>$(String[] args) в D:\Coding\TestImageSharp\TestImageSharp\Program.cs:строка 32

Steps to Reproduce

using SixLabors.Fonts;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.Processing;

bool fontExist = new FontCollection().AddSystemFonts().TryGet("Arial", out var fontFamily);
if (!fontExist)
    throw new Exception("Font doesn't exist");

TextOptions opt = new TextOptions(fontFamily.CreateFont(100, FontStyle.Regular));
string content = "TEST";
IBrush brush;

Image image = new Image<SixLabors.ImageSharp.PixelFormats.Rgba32>(512, 256, Color.Black);

// this work
opt.Origin = new Point(158, 0);
brush = Brushes.Horizontal(Color.Orange);
image.Mutate(x => x.DrawText(opt, content, brush));

opt.Origin = new Point(158, 0);
brush = Brushes.Solid(Color.Orange);
image.Mutate(x => x.DrawText(opt, content, brush));

opt.Origin = new Point(159, 0);
brush = Brushes.Solid(Color.Orange);
image.Mutate(x => x.DrawText(opt, content, brush));

// this don't
opt.Origin = new Point(159, 0);
brush = Brushes.Horizontal(Color.Orange);
image.Mutate(x => x.DrawText(opt, content, brush));

image.SaveAsPng("./res.png");

System Configuration

  • ImageSharp.Drawing version: 1.0.0-beta15
  • Other ImageSharp packages and versions: tried with ImageSharp 2.1.3
  • Environment (Operating system, version and so on): Windows 10
  • .NET Framework version: .NET 6
  • Additional information: -

Computr1x avatar Aug 06 '22 20:08 Computr1x