-
| Hi, not sure it's a bug, but im going to remove my background from my tif file using clipping path. I found the Windows command from the here and it worked fine: Also, someone has the same question with me, the code look like does the extract thing that the command do, but it's not work Just want to convert it to C#, can you help me? | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
| You are very close but the difference here is that you are not reading the clipping path when you clone it. Your command would translate to this: using (var image = new MagickImage("image.jpg"))
{
    // magick identify -quiet -format "%[8BIM:1999,2998:#1]" \
    var clippingPathData = Encoding.ASCII.GetBytes(image.GetClippingPath());
    // ( - <= The '-' means the image is read from stdin
    using (var clippingPath = new MagickImage(clippingPathData))
    {
        // -alpha off
        clippingPath.Alpha(AlphaOption.Off);
        // -negate
        clippingPath.Negate();
        // -morphology erode diamond:1
        clippingPath.Morphology(MorphologyMethod.Erode, Kernel.Diamond, 1);
        // -blur 0x1
        clippingPath.Blur(Channels.All);
        // -level 50x100% )
        clippingPath.Level(new Percentage(50), new Percentage(100));
        // -alpha off
        image.Alpha(AlphaOption.Off);
        // -compose copy_opacity -composite
        image.Composite(clippingPath, CompositeOperator.CopyAlpha);
        image.Write("result.png");
    }
} | 
Beta Was this translation helpful? Give feedback.

You are very close but the difference here is that you are not reading the clipping path when you clone it. Your command would translate to this: