diff --git a/src/Magick.NET/MagickImage.cs b/src/Magick.NET/MagickImage.cs
index a5c2ed051f..8d00101a86 100644
--- a/src/Magick.NET/MagickImage.cs
+++ b/src/Magick.NET/MagickImage.cs
@@ -1094,7 +1094,7 @@ public void AdaptiveSharpen(double radius, double sigma, Channels channels)
/// The height of the pixel neighborhood.
/// Thrown when an error is raised by ImageMagick.
public void AdaptiveThreshold(int width, int height)
- => AdaptiveThreshold(width, height, 0, ImageMagick.Channels.Undefined);
+ => AdaptiveThreshold(width, height, 0.0, ImageMagick.Channels.Undefined);
///
/// Local adaptive threshold image.
@@ -1105,7 +1105,7 @@ public void AdaptiveThreshold(int width, int height)
/// The channel(s) that should be thresholded.
/// Thrown when an error is raised by ImageMagick.
public void AdaptiveThreshold(int width, int height, Channels channels)
- => AdaptiveThreshold(width, height, 0, channels);
+ => AdaptiveThreshold(width, height, 0.0, channels);
///
/// Local adaptive threshold image.
@@ -1128,7 +1128,11 @@ public void AdaptiveThreshold(int width, int height, double bias)
/// The channel(s) that should be thresholded.
/// Thrown when an error is raised by ImageMagick.
public void AdaptiveThreshold(int width, int height, double bias, Channels channels)
- => _nativeInstance.AdaptiveThreshold(width, height, bias, channels);
+ {
+ Throw.IfNegative(nameof(width), width);
+ Throw.IfNegative(nameof(height), height);
+ _nativeInstance.AdaptiveThreshold(width, height, bias, channels);
+ }
///
/// Local adaptive threshold image.
diff --git a/tests/Magick.NET.Tests/MagickImageTests/TheAdaptiveThresholdMethod.cs b/tests/Magick.NET.Tests/MagickImageTests/TheAdaptiveThresholdMethod.cs
index 0192a565ce..1154b10eff 100644
--- a/tests/Magick.NET.Tests/MagickImageTests/TheAdaptiveThresholdMethod.cs
+++ b/tests/Magick.NET.Tests/MagickImageTests/TheAdaptiveThresholdMethod.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,20 @@ public partial class MagickImageTests
{
public class TheAdaptiveThresholdMethod
{
+ [Fact]
+ public void ShouldThrowExceptionWhenWidthIsNegative()
+ {
+ using var image = new MagickImage(Files.MagickNETIconPNG);
+ Assert.Throws("width", () => image.AdaptiveThreshold(-1, 10, 0.0, Channels.Red));
+ }
+
+ [Fact]
+ public void ShouldThrowExceptionWhenHeightIsNegative()
+ {
+ using var image = new MagickImage(Files.MagickNETIconPNG);
+ Assert.Throws("height", () => image.AdaptiveThreshold(10, -1, 0.0, Channels.Red));
+ }
+
[Fact]
public void ShouldThresholdTheImage()
{