This project has moved. For the latest updates, please go here.

Working with clipping paths

Aug 18, 2016 at 9:53 AM
I'm just getting started with Magick.NET. Unfortunately, I cannot figure out how to properly work with clipping paths. Can anyone give me an example of how to Change the Background Color and/or remove the Background?

The Clip()-method doesn't seem to do anything for me.

Also, I'm experiencing a strange bug, when writing a file. My source file is an EPS-file with a resolution of 1144x686. Doing a simple
using (MagickImage image = new MagickImage("img/34667.eps"))
saves the Image as a 275x208 Image.
Aug 18, 2016 at 10:13 AM
Edited Aug 18, 2016 at 10:17 AM
Can you share the EPS image on something like DroPBox/OneDrive? And do you have a file that contains a clipping path that you want to use to remove/change the Background.

I have a very basic example in my unit tests:
Aug 18, 2016 at 11:04 AM
Here is an example file, containing a clipping path:!ArI0AGq7GprKiJU_nxbercKV1mQ_Cw

I don't really get your example. I guess this part
image.Clip("Pfad 1", true);
should remove the background?
For changing the background Color I was assuming I can use the "FloodFill"-Option, after using Clip(), but this isn't working either.
Aug 19, 2016 at 6:56 AM
Will have a look at it when I get home tonight.
Aug 19, 2016 at 7:10 PM
I decided to put my answer in code and comments. Feel free to ask if you need more info.
/* specifying the density befor reading will resolve your size issue */
MagickReadSettings settings = new MagickReadSettings()
  Density = new Density(96)

using (MagickImage image = new MagickImage("34667.eps", settings))
  /* first create a color (make sure it is CMYK when your input image is) */
  MagickColor color = new ColorCMYK(0, Quantum.Max, 0, 0);

  /* the following constructors will be available in the next release */
  // color = new ColorCMYK("#45D10000");
  // color = new ColorCMYK((Percentage)27, (Percentage)82, (Percentage)0, (Percentage)0);

  /* this works for me */
  // image.Clip("Pfad 1", true);
  // image.FloodFill(color, 0, 0);

  /* but this is better */
  image.Clip("Pfad 1", false);
  using (MagickImage background = new MagickImage(color, image.Width, image.Height))
    /* the clipping part makes sure only the pixels you want to be changed are changed */
    image.Composite(background, CompositeOperator.In);

    /* this will work in the next release */
    // image.Composite(background);