This project has moved and is read-only. For the latest updates, please go here.

Masking image with shape

Mar 31, 2016 at 9:50 PM
The packages I reference below are from Nuget.

In version - which must still be using im6 I was able to mask an image with a circle shape like this:
using (var overlay = new MagickImage(localimagePath))
using (var mask = new MagickImage(MagickColor.Transparent, 694, 694)){
            var circle = new DrawableCircle(346,346, 692, 346);
             mask.FillColor = Color.White;

             overlay.Mask = mask;
             overlay.Composite(mask, CompositeOperator.CopyAlpha);
The latest nuget moves to im7 which has a bunch of changes including removal of FillColor for BackgroundColor and changes to Alpha. I have tried the ReadMask function and others, but I cannot get it to render anymore. Most of the documentation for im still seems to be v7, with the update, do you know if I need to switch to readMask or where to look for the correct documentation?

Mar 31, 2016 at 10:30 PM
I am not sure what you are trying to do. Can you add a link to a before/after image?

And Magick.NET has been using IM7 since the 7.X versions started. And I made quite a lot of breaking changes/fixes in the latest releases so you probably need to create the mask differently.
Mar 31, 2016 at 10:43 PM
Starting with :

End up with:

This example isn't exact, but it's the same concept. Going from a square image to a circle.
Mar 31, 2016 at 10:57 PM
The output isn't also exact but the following works for me with the latest version:
using (MagickImage image = new MagickImage("2rnubmq.jpg"))
  using (MagickImage mask = new MagickImage(MagickColors.Black, image.Width, image.Height))
    mask.Settings.FillColor = MagickColors.White;
    mask.Draw(new DrawableCircle(image.Width / 2, image.Height / 2, image.Width, image.Height / 2));

    image.Composite(mask, CompositeOperator.CopyAlpha);
Mar 31, 2016 at 11:04 PM
perfect, that worked for me. Thanks for the quick response.