public static Pair < Integer , Integer > getImageDimensions ( @ NonNull final Context context , @ DrawableRes final int resourceId ) throws IOException { Condition . INSTANCE . ensureNotNull ( context , "The context may not be null" ) ; BitmapFactory . Options options = new BitmapFactory . Options ( ) ; options . inJustDecodeBounds = true ; BitmapFactory . decodeResource ( context . getResources ( ) , resourceId , options ) ; int width = options . outWidth ; int height = options . outHeight ; if ( width == - 1 || height == - 1 ) { throw new IOException ( "Failed to decode image resource with id " + resourceId ) ; } return Pair . create ( width , height ) ; }
Returns the width and height of a specific image resource .