private static int getTrimmedWidth ( BufferedImage img ) { int height = img . getHeight ( ) ; int width = img . getWidth ( ) ; int trimmedWidth = 0 ; for ( int i = 0 ; i < height ; i ++ ) { for ( int j = width - 1 ; j >= 0 ; j -- ) { if ( img . getRGB ( j , i ) != Color . WHITE . getRGB ( ) && j > trimmedWidth ) { trimmedWidth = j ; break ; } } } return trimmedWidth ; }
Get the last non - white X point