I have recently started to learn about Magick.NET, however, I am struggling with understanding how to add masks to an image.
Here is my input image (all blue background for simplicity but in reality I will be using a more complex image):
Here is what I want to create (A house shape with a transparent background):
I understand that I need to add an alpha channel to my "input" image but the below code does not seem to be working.
I just get a completely white image when saving.
Code: Select all
using (MagickImage input = new MagickImage("INPUT.png"),
mask = new MagickImage(MagickColors.White, 500, 500)
)
{
mask.Settings.FillColor = MagickColors.Black;
List<PointD> points = new List<PointD>
{
new PointD(250, 50),
new PointD(150, 150),
new PointD(150, 400),
new PointD(350, 400),
new PointD(350, 150)
};
mask.Draw(new DrawablePolygon(points));
input.Alpha(AlphaOption.Transparent);
input.Composite(mask, CompositeOperator.Alpha);
input.Write("OUTPUT.png");
}