Here you can find the source of trim(BufferedImage image)
private static BufferedImage trim(BufferedImage image)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; public class Main { private static BufferedImage trim(BufferedImage image) { int len;/* w w w. ja va 2s .c o m*/ int x; int y; if (image.getWidth() > image.getHeight()) { len = image.getHeight(); x = (image.getWidth() - len) / 2; y = 0; } else { len = image.getWidth(); x = 0; y = (image.getHeight() - len) / 2; } return image.getSubimage(x, y, len, len); } }