Ringo
Ringo

Reputation: 3965

How to process only one part of image by ImageMagick?

I have an image like below and I want to create a distort effect on it. But just the one part of image, not the whole image.

enter image description here

Thanks.

Upvotes: 1

Views: 803

Answers (1)

dlemstra
dlemstra

Reputation: 8153

I am assuming you are using Magick.NET (https://magick.codeplex.com) because you added the C# tag.

The example below will first cut out the top 123 pixels of your image and applies a distortion to it. After the distortion it will have to be put on top of the source image.

using (MagickImage image = new MagickImage("0nF6D.png"))
{
  using (MagickImage top = image.Clone())
  {
    top.Crop(image.Width, 123, Gravity.North);
    top.Distort(DistortMethod.ScaleRotateTranslate, new double[] { 2, 45 });
    image.Composite(top, Gravity.North, CompositeOperator.SrcOver);
    image.Write("0nF6D.distorted.png");
  }
}

Upvotes: 3

Related Questions