private void Distort(IMagickImage output, PointD[] corners, MagickGeometry inputDimensions, MagickGeometry trimmedDimensions, MagickColor backgroundColor) { MagickGeometry outputDimensions = GetDimensions(output, corners, inputDimensions, trimmedDimensions); double[] arguments = new double[16] { corners[0].X, corners[0].Y, 0, 0, corners[1].X, corners[1].Y, 0, outputDimensions.Height, corners[2].X, corners[2].Y, outputDimensions.Width, outputDimensions.Height, corners[3].X, corners[3].Y, outputDimensions.Width, 0 }; output.VirtualPixelMethod = VirtualPixelMethod.Background; output.BackgroundColor = backgroundColor; if (!DisableViewportCrop) { output.SetArtifact("distort:viewport", GetViewport(arguments, corners).ToString()); } var distortSettings = new DistortSettings() { Bestfit = true }; output.Distort(DistortMethod.Perspective, distortSettings, arguments); output.BorderColor = backgroundColor; output.Border(2); output.ColorFuzz = ColorFuzz; output.Trim(); output.RePage(); }
public void ShouldNotSetTheAttributesWhenTheyAreNotSpecified() { using (var image = new MagickImage()) { var settings = new DistortSettings(); settings.SetImageArtifacts(image); Assert.Empty(image.ArtifactNames); } }
public void ShouldNotSetTheAttributesWhenTheyAreNotSpecified() { using (var image = new MagickImage()) { var settings = new DistortSettings(); settings.SetImageArtifacts(image); Assert.IsNull(image.GetArtifact("distort:scale")); Assert.IsNull(image.GetArtifact("distort:viewport")); } }
public void ShouldSetAnArtifactWhenTheViewportOfTheSettingsIsNotNull() { using (IMagickImage image = new MagickImage(Files.MagickNETIconPNG)) { DistortSettings settings = new DistortSettings() { Viewport = new MagickGeometry(1, 2, 300, 400), }; image.Distort(DistortMethod.Barrel, settings, new double[] { 0, 0, 0, 0, 0 }); Assert.AreEqual("300x400+1+2", image.GetArtifact("distort:viewport")); } }
public void ShouldSetAnArtifactWhenTheScaleOfTheSettingsIsNotNull() { using (IMagickImage image = new MagickImage(Files.MagickNETIconPNG)) { DistortSettings settings = new DistortSettings() { Scale = 5.2, }; image.Distort(DistortMethod.Barrel, settings, new double[] { 0, 0, 0, 0, 0 }); Assert.AreEqual("5.2", image.GetArtifact("distort:scale")); } }
public void ShouldSetViewport() { using (var image = new MagickImage()) { var settings = new DistortSettings() { Viewport = new MagickGeometry(1, 2, 3, 4), }; settings.SetImageArtifacts(image); Assert.AreEqual("3x4+1+2", image.GetArtifact("distort:viewport")); } }
public void ShouldSetScale() { using (var image = new MagickImage()) { var settings = new DistortSettings() { Scale = 4.2, }; settings.SetImageArtifacts(image); Assert.AreEqual("4.2", image.GetArtifact("distort:scale")); } }
public void ShouldRemoveViewport() { using (var image = new MagickImage()) { var settings = new DistortSettings { Viewport = new MagickGeometry(1, 2, 3, 4), }; settings.SetImageArtifacts(image); settings.RemoveImageArtifacts(image); Assert.Empty(image.ArtifactNames); } }
public void ShouldRemoveScale() { using (var image = new MagickImage()) { var settings = new DistortSettings { Scale = 4.2, }; settings.SetImageArtifacts(image); settings.RemoveImageArtifacts(image); Assert.Empty(image.ArtifactNames); } }
public void ShouldSetViewport() { using (var image = new MagickImage()) { var settings = new DistortSettings { Viewport = new MagickGeometry(1, 2, 3, 4), }; ArtifactsHelper.SetImageArtifacts(image, settings); Assert.Single(image.ArtifactNames); Assert.Equal("3x4+1+2", image.GetArtifact("distort:viewport")); } }
public void ShouldSetScale() { using (var image = new MagickImage()) { var settings = new DistortSettings { Scale = 4.2, }; ArtifactsHelper.SetImageArtifacts(image, settings); Assert.Single(image.ArtifactNames); Assert.Equal("4.2", image.GetArtifact("distort:scale")); } }
public void ShouldRemoveViewport() { using (var image = new MagickImage()) { var settings = new DistortSettings() { Viewport = new MagickGeometry(1, 2, 3, 4), }; settings.SetImageArtifacts(image); settings.RemoveImageArtifacts(image); Assert.IsNull(image.GetArtifact("distort:viewport")); } }
public void ShouldRemoveScale() { using (var image = new MagickImage()) { var settings = new DistortSettings() { Scale = 4.2, }; settings.SetImageArtifacts(image); settings.RemoveImageArtifacts(image); Assert.IsNull(image.GetArtifact("distort:scale")); } }
private IMagickImage DistortOverlay(IMagickImage grayShirt, IMagickImage overlay, PointD[] overlayCoordinates, PointD[] tshirtCoordinates) { using (var images = new MagickImageCollection()) { grayShirt.Alpha(AlphaOption.Transparent); grayShirt.BackgroundColor = MagickColors.Transparent; images.Add(grayShirt); var croppedOverlay = CropOverlay(overlay, overlayCoordinates); croppedOverlay.VirtualPixelMethod = VirtualPixelMethod.Transparent; var arguments = CreateArguments(overlayCoordinates, tshirtCoordinates); var distortSettings = new DistortSettings() { Bestfit = true }; croppedOverlay.Distort(DistortMethod.Perspective, distortSettings, arguments); ApplySharpen(croppedOverlay); images.Add(croppedOverlay); return(images.Merge()); } }