Page 1 of 1

Rounded corners in C#/Magick.NET

Posted: 2017-06-03T15:38:05-07:00
by Conno
I've researched this quite extensively, but the Magick.NET documentation is lacking; and there aren't a great deal of examples around t'internet/stackoverflow. Could one of you wizards please assist in converting the following ImageMagick command to C#/.NET?

I've tried, but can't seem to get anywhere! mainly because of confusing naming differences between command line and the c# implementation.

Simply looking to take a jpg or png image, (a portrait/head shot), crop it to transparent circle, and export/save as png.

Code: Select all

 convert thumbnail.gif -alpha set \
    \( +clone -distort DePolar 0 \
       -virtual-pixel HorizontalTile -background None -distort Polar 0 \) \
    -compose Dst_In -composite -trim +repage circle_masked.png
(This was taken from: )

Your time and expertise are much appreciated!

Re: Rounded corners in C#/Magick.NET

Posted: 2017-06-03T15:57:30-07:00
by fmw42
Best to always provide your IM version and platform/OS (Window what?) . Sorry I do not code in C# or .NET.

Re: Rounded corners in C#/Magick.NET

Posted: 2017-06-04T01:19:02-07:00
by Conno
Hi, apologies for neglecting to include that information.

We're running on Windows Sever 2008 (soon to be 2016), .NET Framework 4.5.1, with the Magick.NET Library v7.0.4.701 - the problem is, I'm not sure which version of ImageMagick the .NET library is wrapping (I presume the latest version as of Feb 12, 2017 - as that's the date of this version of the .NET lib)

Re: Rounded corners in C#/Magick.NET

Posted: 2017-06-04T12:22:14-07:00
by Conno
I solved the issue with a lot of trial and error, for anyone who wants to do the same thing in the future:

Code: Select all

image.Format = MagickFormat.Png;
MagickImage copy = image.Clone();

copy.Distort(DistortMethod.DePolar, 0);
copy.VirtualPixelMethod = VirtualPixelMethod.HorizontalTile;
copy.BackgroundColor = MagickColors.None;
copy.Distort(DistortMethod.Polar, 0);

image.Compose = CompositeOperator.DstIn;
image.Composite(copy, CompositeOperator.CopyAlpha);