.net – Image library that will auto-crop


I'm looking for a .Net library that will accept an image or filename and an aspect ratio, and crop the image to that aspect ratio. That's the easy part: I could do it myself. But I also want it to show a little intelligence in choosing exactly what content gets cropped, even if it's just picking which edge to slice.

This is for a personal project, and the pain isn't high enough to justify spending any money on it, but if you can recommend a for-pay tool go ahead. Maybe someone else will find the suggestion useful.

Best Solution

Disclaimer: I work for a .NET Imaging vendor (Atalasoft)

It depends on what kind of image you are talking about. If you are talking about 1-bit document images (like faxes or scans) we can do this.

If you are talking about photographs, our product doesn't do this, but you might be looking for Seam carving. I wrote this application


with our library that could be ported to just using the built-in .NET images with some work.

The idea of seam carving is to find connected paths in the image with the least interesting variation from the surrounding pixels. In the normal implementation, you would pick a continuous (but not necessarily vertical) path and remove it. If you wanted a crop, you could find the area with the least energy and remove it. My code shows how to calculate the energy of a pixel and path (how different it is from it's surrounding pixels)

If you look up seam carving, you will find some free implementations out there.