public static Pair < Integer , Integer > getImageDimensions ( @ NonNull final File file ) throws IOException { Condition . INSTANCE . ensureNotNull ( file , "The file may not be null" ) ; Condition . INSTANCE . ensureFileIsNoDirectory ( file , "The file must exist and must not be a directory" ) ; String path = file . getPath ( ) ; BitmapFactory . Options options = new BitmapFactory . Options ( ) ; options . inJustDecodeBounds = true ; BitmapFactory . decodeFile ( path , options ) ; int width = options . outWidth ; int height = options . outHeight ; if ( width == - 1 || height == - 1 ) { throw new IOException ( "Failed to decode image \"" + path + "\"" ) ; } return Pair . create ( width , height ) ; }
Returns the width and height of a specific image file .