Crop An Image Into A Circle

Nov 4, 2013 at 4:59 AM
I am attempting to translate the ImageMagick command line parameters to the Magick.NET classes and have had pretty good success except for one. I want to take a square image and crop it into a circle where the part outside of the circle is transparent. An example can be found here http://stackoverflow.com/questions/999251/crop-or-mask-an-image-into-a-circle . On this page it lists the ImageMagick command line code as the following:

convert -size 200x200 xc:none -fill walter.jpg -draw "circle 100,100 100,1" circle_thumb.png

I have been able to do this in C# except for the "xc" parameter. Here is my code so far:
        string file = @"C:\\Walter.jpg";
        MagickImage image = new MagickImage(file);
        image.Resize(200,200);
        image.FillColor = new MagickColor(Color.Transparent);
        DrawableCircle dc = new DrawableCircle(100, 100, 100, 1);
        image.Draw(dc);
Where can I find the class for "xc" or "Canvas"? Or maybe you have a better idea of how to do what I am attempting?

I am using the 64 bit dll from the nuget package.
Coordinator
Nov 4, 2013 at 6:51 AM
The xc:none is an alias for a file name. I haven't tested this but it should be something like this:
MagickReadSettings settings = new MagickReadSettings();
settings.Width = 200;
settings.Height = 200;
using (MagickImage image = new MagickImage("xc:none", settings))
{
  using(MagickImage fill = new MagickImage(@"C:\\Walter.jpg"))
  {
    image.FloodFill(fill, 0, 0);
  }
  DrawableCircle dc = new DrawableCircle(100, 100, 100, 1);
  image.Draw(dc);
  image.Write(@"C:\circle_thumb.png");
}
Oct 8, 2014 at 4:09 PM
Edited Oct 8, 2014 at 4:11 PM
dlemstra wrote:
The xc:none is an alias for a file name. I haven't tested this but it should be something like this:
MagickReadSettings settings = new MagickReadSettings();
settings.Width = 200;
settings.Height = 200;
using (MagickImage image = new MagickImage("xc:none", settings))
{
  using(MagickImage fill = new MagickImage(@"C:\\Walter.jpg"))
  {
    image.FloodFill(fill, 0, 0);
  }
  DrawableCircle dc = new DrawableCircle(100, 100, 100, 1);
  image.Draw(dc);
  image.Write(@"C:\circle_thumb.png");
}
This is what i currently have and it is creating an image with a black circle on top of the image and doing nothing for cropping the actual image that i'm trying to crop. Can anyone point me in the right direction?
using (MagickImage magickImage = new MagickImage(imageByte))
            {
                MagickReadSettings settings = new MagickReadSettings { Width = magickImage.Width, Height = magickImage.Height };
                using (var newImage = new MagickImage("xc:none", settings))
                {
                    using (MagickImage fill = new MagickImage(magickImage))
                    {
                        newImage.FloodFill(fill, 0, 0);
                    }
                    DrawableCircle dc = new DrawableCircle(180, 180, 180, 1);
                    newImage.Draw(dc);
                    newImage.Format = MagickFormat.Png8;
                    //imgTarget = magickImage.ToBitmap(ImageFormat.Png);
                    //return imgTarget;
                    return newImage.ToBitmap(ImageFormat.Png);
                }
            }