textclassifier/src/main/java/androidx/textclassifier/TextClassification.java
@Nullable
    private static Bitmap drawableToBitmap(@Nullable Drawable drawable, int maxDims) {
        if (drawable == null) {
            return null;
        }
        final int actualWidth = Math.max(1, drawable.getIntrinsicWidth());
        final int actualHeight = Math.max(1, drawable.getIntrinsicHeight());
        final double scaleWidth = ((double) maxDims) / actualWidth;
        final double scaleHeight = ((double) maxDims) / actualHeight;
        final double scale = Math.min(1.0, Math.min(scaleWidth, scaleHeight));
        final int width = (int) (actualWidth * scale);
        final int height = (int) (actualHeight * scale);
        if (drawable instanceof BitmapDrawable) {
            final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
            if (actualWidth != width || actualHeight != height) {
                return Bitmap.createScaledBitmap(
                        bitmapDrawable.getBitmap(), width, height, /*filter=*/false);
            } else {
                return bitmapDrawable.getBitmap();
            }
        } else {
            final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            final Canvas canvas = new Canvas(bitmap);
            drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            drawable.draw(canvas);
            return bitmap;
        }
    }
/**
     * Returns a Bitmap representation of the Drawable
     *
     * @param drawable The drawable to convert.
     * @param maxDims The maximum edge length of the resulting bitmap (in pixels).
     */
Returns a Bitmap representation of the Drawable
@param drawable The drawable to convert.
@param maxDims The maximum edge length of the resulting bitmap (in pixels).
Returns a Bitmap representation of the Drawable @param drawable The drawable to convert . @param maxDims The maximum edge length of the resulting bitmap ( in pixels ) .
@Nullable
    private static Bitmap drawableToBitmap(@Nullable Drawable drawable, int maxDims) {
        if (drawable == null) {
            return null;
        }
        final int actualWidth = Math.max(1, drawable.getIntrinsicWidth());
        final int actualHeight = Math.max(1, drawable.getIntrinsicHeight());
        final double scaleWidth = ((double) maxDims) / actualWidth;
        final double scaleHeight = ((double) maxDims) / actualHeight;
        final double scale = Math.min(1.0, Math.min(scaleWidth, scaleHeight));
        final int width = (int) (actualWidth * scale);
        final int height = (int) (actualHeight * scale);
        if (drawable instanceof BitmapDrawable) {
            final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
            if (actualWidth != width || actualHeight != height) {
                return Bitmap.createScaledBitmap(
                        bitmapDrawable.getBitmap(), width, height, /*filter=*/false);
            } else {
                return bitmapDrawable.getBitmap();
            }
        } else {
            final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            final Canvas canvas = new Canvas(bitmap);
            drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            drawable.draw(canvas);
            return bitmap;
        }
    }
@ Nullable private static Bitmap drawableToBitmap ( @ Nullable Drawable drawable , int maxDims ) { if ( drawable == null ) { return null ; } final int actualWidth = Math . max ( 1 , drawable . getIntrinsicWidth ( ) ) ; final int actualHeight = Math . max ( 1 , drawable . getIntrinsicHeight ( ) ) ; final double scaleWidth = ( ( double ) maxDims ) / actualWidth ; final double scaleHeight = ( ( double ) maxDims ) / actualHeight ; final double scale = Math . min ( 1.0 , Math . min ( scaleWidth , scaleHeight ) ) ; final int width = ( int ) ( actualWidth * scale ) ; final int height = ( int ) ( actualHeight * scale ) ; if ( drawable instanceof BitmapDrawable ) { final BitmapDrawable bitmapDrawable = ( BitmapDrawable ) drawable ; if ( actualWidth != width || actualHeight != height ) { return Bitmap . createScaledBitmap ( bitmapDrawable . getBitmap ( ) , width , height , /*filter=*/ false ) ; } else { return bitmapDrawable . getBitmap ( ) ; } } else { final Bitmap bitmap = Bitmap . createBitmap ( width , height , Bitmap . Config . ARGB_8888 ) ; final Canvas canvas = new Canvas ( bitmap ) ; drawable . setBounds ( 0 , 0 , canvas . getWidth ( ) , canvas . getHeight ( ) ) ; drawable . draw ( canvas ) ; return bitmap ; } }
Returns a Bitmap representation of the Drawable
 @param drawable The drawable to convert.
Returns a Bitmap representation of the Drawable @param drawable The drawable to convert .