I have a TIFF with one clipping path stored in the 8BimProfile. Now I want to crop this image along the clipping path.
What I tried
My first approach was to use the MagickImage Clip() method, which seems to do nothing:
using (var image = new MagickImage(pathOfFileToClip))
{
image.Clip();
image.Write(targetPath);
}
The workaround I am currently using calls the ImageMagick convert.exe tool:
var wrappedFilePath = "\"" + pathOfFileToClip + "\"";
var arguments = wrappedFilePath + " -alpha transparent -clip -alpha opaque -strip " + wrappedFilePath;
var process = new System.Diagnostics.Process();
var startInfo = new System.Diagnostics.ProcessStartInfo
{
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
FileName = @"C:\Program Files\ImageMagick-6.9.3-Q16\convert.exe",
Arguments = arguments
};
process.StartInfo = startInfo;
process.Start();
This works nicely and crops the image the way I want it. But how can I get this to work without the EXE?
Just taking the command line arguments like this did not work either:
using (var image = new MagickImage(pathOfFileToClip))
{
image.AlphaColor = new MagickColor(Color.Transparent);
image.Clip();
image.AlphaColor = new MagickColor(Color.Black);
image.Strip();
image.Write(targetPath);
}
Any suggestions or links to working solutions are appreciated.