SixLabors/ImageSharp · error · ImageProcessingException

The OilPaintProcessor failed. The most likely reason is…

Error message

The OilPaintProcessor failed. The most likely reason is that a pixel component was outside of its' allowed range.

What it means

OilPaintingProcessor wraps its per-frame pixel operations in try/catch and rethrows any inner failure as ImageProcessingException. The kernel-based levels accumulation can only fail if a computed level index falls outside the levels array, i.e. a pixel component was out of range. This usually indicates corrupted input pixel data or an internal kernel problem, so the library reports the original exception as inner.

Solutions

  1. Inspect the InnerException to find the real failure
  2. Ensure input pixels come from normal Image<TPixel> decoding, not hand-written buffer writes
  3. If a custom IPixel<TPixel> implementation is involved, fix its component clamping so all components stay within [0,1] scaled range
  4. Reduce the oil paint levels parameter and retry to see if the failure is level-count dependent

Example fix

// before
image.Mutate(x => x.OilPaint(levels, brushSize));
// after
try
{
    image.Mutate(x => x.OilPaint(levels, brushSize));
}
catch (ImageProcessingException ex)
{
    // inspect ex.InnerException for the real pixel-level failure
    throw;
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (image is null || image.Width == 0 || image.Height == 0) throw new InvalidOperationException("Image not loaded.");

Try / catch

try
{
    image.Mutate(x => x.OilPaint(levels, brushSize));
}
catch (ImageProcessingException ex)
{
    // log ex.InnerException.StackTrace for the underlying pixel failure
    throw;
}

Prevention

When it happens

Trigger: Calling Mutate/Apply with OilPaintingProcessor when the underlying pixel buffer contains values outside the component range, or when the levels lookup in the parallel kernel throws (index mismatch between pixel type and levels array).

Common situations: Processing images whose pixel data was produced by buggy custom IPixel implementations or raw buffer manipulation; running on images with unusual pixel formats converted unexpectedly; downstream memory corruption from other unsafe code.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13). Data as JSON: /api/errors/308a9b4a56acf7fb. Report an issue: GitHub.

Appendix: source

Thrown at src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs:55

    {
        int levels = Math.Clamp(this.definition.Levels, 1, 255);
        int brushSize = Math.Clamp(this.definition.BrushSize, 1, Math.Min(source.Width, source.Height));

        using Buffer2D<TPixel> targetPixels = this.Configuration.MemoryAllocator.Allocate2D<TPixel>(source.Size);

        source.CopyTo(targetPixels);

        RowIntervalOperation operation = new(this.SourceRectangle, targetPixels, source.PixelBuffer, this.Configuration, brushSize >> 1, levels);
        try
        {
            ParallelRowIterator.IterateRowIntervals(
            this.Configuration,
            this.SourceRectangle,
            in operation);
        }
        catch (Exception ex)
        {
            throw new ImageProcessingException("The OilPaintProcessor failed. The most likely reason is that a pixel component was outside of its' allowed range.", ex);
        }

        Buffer2D<TPixel>.SwapOrCopyContent(source.PixelBuffer, targetPixels);
    }

    /// <summary>
    /// A <see langword="struct"/> implementing the convolution logic for <see cref="OilPaintingProcessor{T}"/>.
    /// </summary>
    private readonly struct RowIntervalOperation : IRowIntervalOperation
    {
        private readonly Rectangle bounds;
        private readonly Buffer2D<TPixel> targetPixels;
        private readonly Buffer2D<TPixel> source;
        private readonly Configuration configuration;
        private readonly int radius;
        private readonly int levels;

        [MethodImpl(InliningOptions.ShortMethod)]

View on GitHub (pinned to 59ce6af6fc)