Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Magick.NET/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6252,7 +6252,12 @@ public void Spread(PixelInterpolateMethod method, double radius)
/// <param name="height">The height of the pixel neighborhood.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void Statistic(StatisticType type, int width, int height)
=> _nativeInstance.Statistic(type, width, height);
{
Throw.IfNegative(nameof(width), width);
Throw.IfNegative(nameof(height), height);

_nativeInstance.Statistic(type, width, height);
}

/// <summary>
/// Returns the image statistics.
Expand Down
17 changes: 17 additions & 0 deletions tests/Magick.NET.Tests/MagickImageTests/TheStatisticMethod.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

using System;
using ImageMagick;
using Xunit;

Expand All @@ -10,6 +11,22 @@ public partial class MagickImageTests
{
public class TheStatisticMethod
{
[Fact]
public void ShouldThrowExceptionWhenWidthIsNegative()
{
using var image = new MagickImage(Files.NoisePNG);

Assert.Throws<ArgumentException>("width", () => image.Statistic(StatisticType.Minimum, -1, 1));
}

[Fact]
public void ShouldThrowExceptionWhenHeightIsNegative()
{
using var image = new MagickImage(Files.NoisePNG);

Assert.Throws<ArgumentException>("height", () => image.Statistic(StatisticType.Minimum, 10, -1));
}

[Fact]
public void ShouldChangePixels()
{
Expand Down