Here you can find the source of cutToSquare(BufferedImage src)
public static BufferedImage cutToSquare(BufferedImage src)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; public class Main { public static BufferedImage cutToSquare(BufferedImage src) { int width = src.getWidth(); int height = src.getHeight(); if (width == height) return src; BufferedImage result = null; if (width > height) { int cut = (width - height) / 2; result = src.getSubimage(cut, 0, height, height); } else {//from ww w. j a v a 2 s . c o m int cut = (height - width) / 2; result = src.getSubimage(0, cut, width, width); } return result; } }