Rounded corners in C#/Magick.NET

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
Conno
Posts: 3
Joined: 2017-06-03T15:28:34-07:00
Authentication code: 1151

Rounded corners in C#/Magick.NET

Post 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: http://www.imagemagick.org/Usage/thumbnails/#rounded )

Your time and expertise are much appreciated!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Rounded corners in C#/Magick.NET

Post by fmw42 »

Best to always provide your IM version and platform/OS (Window what?) . Sorry I do not code in C# or .NET.
Conno
Posts: 3
Joined: 2017-06-03T15:28:34-07:00
Authentication code: 1151

Re: Rounded corners in C#/Magick.NET

Post 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)
Conno
Posts: 3
Joined: 2017-06-03T15:28:34-07:00
Authentication code: 1151

Re: Rounded corners in C#/Magick.NET

Post 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;
image.Alpha(AlphaOption.Set);
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);
Post Reply