public static BufferedImage trim(BufferedImage img) {
    int width = getTrimmedWidth(img);
    int height = getTrimmedHeight(img);
    int xStart = getTrimmedXStart(img);
    int yStart = getTrimmedYStart(img);

    BufferedImage newImg = new BufferedImage(width - xStart, height - yStart, BufferedImage.TYPE_INT_ARGB);
    Graphics g = newImg.createGraphics();
    g.drawImage(img, 0 - xStart, 0 - yStart, null);

    return newImg;
  }
public static BufferedImage trim ( BufferedImage img ) { int width = getTrimmedWidth ( img ) ; int height = getTrimmedHeight ( img ) ; int xStart = getTrimmedXStart ( img ) ; int yStart = getTrimmedYStart ( img ) ; BufferedImage newImg = new BufferedImage ( width - xStart , height - yStart , BufferedImage . TYPE_INT_ARGB ) ; Graphics g = newImg . createGraphics ( ) ; g . drawImage ( img , 0 - xStart , 0 - yStart , null ) ; return newImg ; }
Trims an image (removes all leading and trailing white spaces)
@param img Image in memory
@return Trimmed image