diff --git a/src/Magick.NET/MagickImage.cs b/src/Magick.NET/MagickImage.cs
index e873129de6..1104af7b7b 100644
--- a/src/Magick.NET/MagickImage.cs
+++ b/src/Magick.NET/MagickImage.cs
@@ -6252,7 +6252,12 @@ public void Spread(PixelInterpolateMethod method, double radius)
/// The height of the pixel neighborhood.
/// Thrown when an error is raised by ImageMagick.
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);
+ }
///
/// Returns the image statistics.
diff --git a/tests/Magick.NET.Tests/MagickImageTests/TheStatisticMethod.cs b/tests/Magick.NET.Tests/MagickImageTests/TheStatisticMethod.cs
index f034f637c9..7ef3011552 100644
--- a/tests/Magick.NET.Tests/MagickImageTests/TheStatisticMethod.cs
+++ b/tests/Magick.NET.Tests/MagickImageTests/TheStatisticMethod.cs
@@ -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;
@@ -10,6 +11,22 @@ public partial class MagickImageTests
{
public class TheStatisticMethod
{
+ [Fact]
+ public void ShouldThrowExceptionWhenWidthIsNegative()
+ {
+ using var image = new MagickImage(Files.NoisePNG);
+
+ Assert.Throws("width", () => image.Statistic(StatisticType.Minimum, -1, 1));
+ }
+
+ [Fact]
+ public void ShouldThrowExceptionWhenHeightIsNegative()
+ {
+ using var image = new MagickImage(Files.NoisePNG);
+
+ Assert.Throws("height", () => image.Statistic(StatisticType.Minimum, 10, -1));
+ }
+
[Fact]
public void ShouldChangePixels()
{