-
-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CloneArea to MagickImage that will replace the Clone overload w…
…ith a MagickGeometry.
- Loading branch information
Showing
4 changed files
with
155 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
tests/Magick.NET.Tests/MagickImageTests/TheCloneAreaMethod.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using ImageMagick; | ||
using Xunit; | ||
|
||
namespace Magick.NET.Tests; | ||
|
||
public partial class MagickImageTests | ||
{ | ||
public class TheCloneAreaMethod | ||
{ | ||
public class WithGeometry | ||
{ | ||
[Fact] | ||
public void ShouldCloneTheSpecifiedGeometry() | ||
{ | ||
using var icon = new MagickImage(Files.MagickNETIconPNG); | ||
using var area = icon.Clone(); | ||
area.Crop(64, 64, Gravity.Southeast); | ||
area.ResetPage(); | ||
area.Crop(64, 32, Gravity.North); | ||
|
||
using var part = icon.CloneArea(new MagickGeometry(64, 64, 64, 32)); | ||
|
||
Assert.Equal(area.Width, part.Width); | ||
Assert.Equal(area.Height, part.Height); | ||
|
||
Assert.Equal(0.0, area.Compare(part, ErrorMetric.RootMeanSquared)); | ||
} | ||
} | ||
|
||
public class WithWidthAndHeight | ||
{ | ||
[Fact] | ||
public void ShouldClonePartOfTheImageWhenWidthAndHeightAreSpecified() | ||
{ | ||
using var icon = new MagickImage(Files.MagickNETIconPNG); | ||
using var area = icon.Clone(); | ||
area.Crop(32, 64, Gravity.Northwest); | ||
|
||
Assert.Equal(32U, area.Width); | ||
Assert.Equal(64U, area.Height); | ||
|
||
using var part = icon.CloneArea(32, 64); | ||
|
||
Assert.Equal(area.Width, part.Width); | ||
Assert.Equal(area.Height, part.Height); | ||
Assert.Equal(0.0, area.Compare(part, ErrorMetric.RootMeanSquared)); | ||
Assert.Equal(8192, part.ToByteArray(MagickFormat.Rgba).Length); | ||
} | ||
} | ||
|
||
public class WithWidthAndHeightAndOffset | ||
{ | ||
[Fact] | ||
public void ShouldCloneUsingTheSpecifiedOffset() | ||
{ | ||
using var icon = new MagickImage(Files.MagickNETIconPNG); | ||
using var area = icon.Clone(); | ||
area.Crop(64, 64, Gravity.Southeast); | ||
area.ResetPage(); | ||
area.Crop(64, 32, Gravity.North); | ||
|
||
using var part = icon.CloneArea(64, 64, 64, 32); | ||
|
||
Assert.Equal(area.Width, part.Width); | ||
Assert.Equal(area.Height, part.Height); | ||
|
||
Assert.Equal(0.0, area.Compare(part, ErrorMetric.RootMeanSquared)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters