答案 0 :(得分:3)
我建议采用以下方法:
trim
*如果示例图片中的黄色区域实际上是透明的,您可以在以下代码中留下fuzz = 0
,否则您必须调整该值以确保删除所有不需要的区域。< / p>
string srcImageFullPath = "c:\input.png";
int fuzz = 0;
string destImageFullPath = "c:\output.png";
// Read image from file
using (MagickImage image = new MagickImage(srcImageFullPath))
{
//save height/width of the original image
int height = image.Page.Height;
int width = image.Page.Width;
//set fuzz percentage
image.ColorFuzz = new ImageMagick.Percentage(fuzz);
//trim borders
image.Trim();
//resize image to original size
MagickGeometry size = new MagickGeometry(width, height);
size.IgnoreAspectRatio = true;
image.Resize(size);
// Save the result
image.Write(destImageFullPath);
}
在下图中,您可以看到左侧的原始图像,以及右侧调整大小后的图像:
备注的