public static BufferedImage cropImage(BufferedImage image,int cropWidth,int cropHeight){
  BufferedImage retImg=null;
  int width=0;
  int height=0;
  width=image.getWidth();
  height=image.getHeight();
  retImg=new BufferedImage(cropWidth,cropHeight,BufferedImage.TYPE_INT_RGB);
  for (int i=0; i < cropWidth; i++) {
    for (int j=0; j < cropHeight; j++) {
      if (i < width && j < height) {
        retImg.setRGB(i,j,image.getRGB(i,j));
      }
 else {
        retImg.setRGB(i,j,0);
      }
    }
  }
  return retImg;
}

public static BufferedImage cropImage ( BufferedImage image , int cropWidth , int cropHeight ) { BufferedImage retImg = null ; int width = 0 ; int height = 0 ; width = image . getWidth ( ) ; height = image . getHeight ( ) ; retImg = new BufferedImage ( cropWidth , cropHeight , BufferedImage . TYPE_INT_RGB ) ; for ( int i = 0 ; i < cropWidth ; i ++ ) { for ( int j = 0 ; j < cropHeight ; j ++ ) { if ( i < width && j < height ) { retImg . setRGB ( i , j , image . getRGB ( i , j ) ) ; } else { retImg . setRGB ( i , j , 0 ) ; } } } return retImg ; }
method crop an image to the given dimensions . if dimensions are more than the input image size , then the image gets padded with black color
