transition/src/main/java/androidx/transition/TransitionUtils.java
private static Bitmap createViewBitmap(View view, Matrix matrix, RectF bounds,
            ViewGroup sceneRoot) {
        final boolean addToOverlay;
        final boolean sceneRootIsAttached;
        if (HAS_IS_ATTACHED_TO_WINDOW) {
            addToOverlay = !view.isAttachedToWindow();
            sceneRootIsAttached = sceneRoot == null ? false : sceneRoot.isAttachedToWindow();
        } else {
            addToOverlay = false;
            sceneRootIsAttached = false;
        }
        ViewGroup parent = null;
        int indexInParent = 0;
        if (HAS_OVERLAY && addToOverlay) {
            if (!sceneRootIsAttached) {
                return null;
            }
            parent = (ViewGroup) view.getParent();
            indexInParent = parent.indexOfChild(view);
            sceneRoot.getOverlay().add(view);
        }
        Bitmap bitmap = null;
        int bitmapWidth = Math.round(bounds.width());
        int bitmapHeight = Math.round(bounds.height());
        if (bitmapWidth > 0 && bitmapHeight > 0) {
            float scale = Math.min(1f, ((float) MAX_IMAGE_SIZE) / (bitmapWidth * bitmapHeight));
            bitmapWidth = Math.round(bitmapWidth * scale);
            bitmapHeight = Math.round(bitmapHeight * scale);
            matrix.postTranslate(-bounds.left, -bounds.top);
            matrix.postScale(scale, scale);

            if (HAS_PICTURE_BITMAP) {
                // Hardware rendering
                final Picture picture = new Picture();
                final Canvas canvas = picture.beginRecording(bitmapWidth, bitmapHeight);
                canvas.concat(matrix);
                view.draw(canvas);
                picture.endRecording();
                bitmap = Bitmap.createBitmap(picture);
            } else {
                // Software rendering
                bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(bitmap);
                canvas.concat(matrix);
                view.draw(canvas);
            }
        }
        if (HAS_OVERLAY && addToOverlay) {
            sceneRoot.getOverlay().remove(view);
            parent.addView(view, indexInParent);
        }
        return bitmap;
    }
/**
     * Creates a Bitmap of the given view, using the Matrix matrix to transform to the local
     * coordinates. <code>matrix</code> will be modified during the bitmap creation.
     *
     * <p>If the bitmap is large, it will be scaled uniformly down to at most 1MB size.</p>
     *
     * @param view   The view to create a bitmap for.
     * @param matrix The matrix converting the view local coordinates to the coordinates that
     *               the bitmap will be displayed in. <code>matrix</code> will be modified before
     *               returning.
     * @param bounds The bounds of the bitmap in the destination coordinate system (where the
     *               view should be presented. Typically, this is matrix.mapRect(viewBounds);
     * @return A bitmap of the given view or null if bounds has no width or height.
     */
Creates a Bitmap of the given view, using the Matrix matrix to transform to the local
coordinates. matrix will be modified during the bitmap creation.

If the bitmap is large, it will be scaled uniformly down to at most 1MB size.

@param view   The view to create a bitmap for.
@param matrix The matrix converting the view local coordinates to the coordinates that
the bitmap will be displayed in. matrix will be modified before
returning.
@param bounds The bounds of the bitmap in the destination coordinate system (where the
view should be presented. Typically, this is matrix.mapRect(viewBounds);
@return A bitmap of the given view or null if bounds has no width or height.
Creates a Bitmap of the given view using the Matrix matrix to transform to the local coordinates . matrix will be modified during the bitmap creation . If the bitmap is large it will be scaled uniformly down to at most 1MB size . @param view The view to create a bitmap for . @param matrix The matrix converting the view local coordinates to the coordinates that the bitmap will be displayed in . matrix will be modified before returning . @param bounds The bounds of the bitmap in the destination coordinate system ( where the view should be presented . Typically this is matrix . mapRect ( viewBounds ) ; @return A bitmap of the given view or null if bounds has no width or height .
private static Bitmap createViewBitmap(View view, Matrix matrix, RectF bounds,
            ViewGroup sceneRoot) {
        final boolean addToOverlay;
        final boolean sceneRootIsAttached;
        if (HAS_IS_ATTACHED_TO_WINDOW) {
            addToOverlay = !view.isAttachedToWindow();
            sceneRootIsAttached = sceneRoot == null ? false : sceneRoot.isAttachedToWindow();
        } else {
            addToOverlay = false;
            sceneRootIsAttached = false;
        }
        ViewGroup parent = null;
        int indexInParent = 0;
        if (HAS_OVERLAY && addToOverlay) {
            if (!sceneRootIsAttached) {
                return null;
            }
            parent = (ViewGroup) view.getParent();
            indexInParent = parent.indexOfChild(view);
            sceneRoot.getOverlay().add(view);
        }
        Bitmap bitmap = null;
        int bitmapWidth = Math.round(bounds.width());
        int bitmapHeight = Math.round(bounds.height());
        if (bitmapWidth > 0 && bitmapHeight > 0) {
            float scale = Math.min(1f, ((float) MAX_IMAGE_SIZE) / (bitmapWidth * bitmapHeight));
            bitmapWidth = Math.round(bitmapWidth * scale);
            bitmapHeight = Math.round(bitmapHeight * scale);
            matrix.postTranslate(-bounds.left, -bounds.top);
            matrix.postScale(scale, scale);
            if (HAS_PICTURE_BITMAP) {
                final Picture picture = new Picture();
                final Canvas canvas = picture.beginRecording(bitmapWidth, bitmapHeight);
                canvas.concat(matrix);
                view.draw(canvas);
                picture.endRecording();
                bitmap = Bitmap.createBitmap(picture);
            } else {
                bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(bitmap);
                canvas.concat(matrix);
                view.draw(canvas);
            }
        }
        if (HAS_OVERLAY && addToOverlay) {
            sceneRoot.getOverlay().remove(view);
            parent.addView(view, indexInParent);
        }
        return bitmap;
    }
private static Bitmap createViewBitmap ( View view , Matrix matrix , RectF bounds , ViewGroup sceneRoot ) { final boolean addToOverlay ; final boolean sceneRootIsAttached ; if ( HAS_IS_ATTACHED_TO_WINDOW ) { addToOverlay = ! view . isAttachedToWindow ( ) ; sceneRootIsAttached = sceneRoot == null ? false : sceneRoot . isAttachedToWindow ( ) ; } else { addToOverlay = false ; sceneRootIsAttached = false ; } ViewGroup parent = null ; int indexInParent = 0 ; if ( HAS_OVERLAY && addToOverlay ) { if ( ! sceneRootIsAttached ) { return null ; } parent = ( ViewGroup ) view . getParent ( ) ; indexInParent = parent . indexOfChild ( view ) ; sceneRoot . getOverlay ( ) . add ( view ) ; } Bitmap bitmap = null ; int bitmapWidth = Math . round ( bounds . width ( ) ) ; int bitmapHeight = Math . round ( bounds . height ( ) ) ; if ( bitmapWidth > 0 && bitmapHeight > 0 ) { float scale = Math . min ( 1f , ( ( float ) MAX_IMAGE_SIZE ) / ( bitmapWidth * bitmapHeight ) ) ; bitmapWidth = Math . round ( bitmapWidth * scale ) ; bitmapHeight = Math . round ( bitmapHeight * scale ) ; matrix . postTranslate ( - bounds . left , - bounds . top ) ; matrix . postScale ( scale , scale ) ; if ( HAS_PICTURE_BITMAP ) { final Picture picture = new Picture ( ) ; final Canvas canvas = picture . beginRecording ( bitmapWidth , bitmapHeight ) ; canvas . concat ( matrix ) ; view . draw ( canvas ) ; picture . endRecording ( ) ; bitmap = Bitmap . createBitmap ( picture ) ; } else { bitmap = Bitmap . createBitmap ( bitmapWidth , bitmapHeight , Bitmap . Config . ARGB_8888 ) ; Canvas canvas = new Canvas ( bitmap ) ; canvas . concat ( matrix ) ; view . draw ( canvas ) ; } } if ( HAS_OVERLAY && addToOverlay ) { sceneRoot . getOverlay ( ) . remove ( view ) ; parent . addView ( view , indexInParent ) ; } return bitmap ; }
Creates a Bitmap of the given view, using the Matrix matrix to transform to the local
 coordinates.
Creates a Bitmap of the given view using the Matrix matrix to transform to the local coordinates .
// Hardware rendering // Software rendering