compat/src/main/java/androidx/core/app/SharedElementCallback.java
public Parcelable onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix,
            RectF screenBounds) {
        if (sharedElement instanceof ImageView) {
            ImageView imageView = ((ImageView) sharedElement);
            Drawable d = imageView.getDrawable();
            Drawable bg = imageView.getBackground();
            if (d != null && bg == null) {
                Bitmap bitmap = createDrawableBitmap(d);
                if (bitmap != null) {
                    Bundle bundle = new Bundle();
                    bundle.putParcelable(BUNDLE_SNAPSHOT_BITMAP, bitmap);
                    bundle.putString(BUNDLE_SNAPSHOT_IMAGE_SCALETYPE,
                            imageView.getScaleType().toString());
                    if (imageView.getScaleType() == ScaleType.MATRIX) {
                        Matrix matrix = imageView.getImageMatrix();
                        float[] values = new float[9];
                        matrix.getValues(values);
                        bundle.putFloatArray(BUNDLE_SNAPSHOT_IMAGE_MATRIX, values);
                    }
                    return bundle;
                }
            }
        }
        int bitmapWidth = Math.round(screenBounds.width());
        int bitmapHeight = Math.round(screenBounds.height());
        Bitmap bitmap = null;
        if (bitmapWidth > 0 && bitmapHeight > 0) {
            float scale = Math.min(1f, ((float) MAX_IMAGE_SIZE) / (bitmapWidth * bitmapHeight));
            bitmapWidth = (int) (bitmapWidth * scale);
            bitmapHeight = (int) (bitmapHeight * scale);
            if (mTempMatrix == null) {
                mTempMatrix = new Matrix();
            }
            mTempMatrix.set(viewToGlobalMatrix);
            mTempMatrix.postTranslate(-screenBounds.left, -screenBounds.top);
            mTempMatrix.postScale(scale, scale);
            bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            canvas.concat(mTempMatrix);
            sharedElement.draw(canvas);
        }
        return bitmap;
    }
/**
     * Creates a snapshot of a shared element to be used by the remote Activity and reconstituted
     * with {@link #onCreateSnapshotView(android.content.Context, android.os.Parcelable)}. A
     * null return value will mean that the remote Activity will have a null snapshot View in
     * {@link #onSharedElementStart(java.util.List, java.util.List, java.util.List)} and
     * {@link #onSharedElementEnd(java.util.List, java.util.List, java.util.List)}.
     *
     * <p>This is not called for Fragment Transitions.</p>
     *
     * @param sharedElement The shared element View to create a snapshot for.
     * @param viewToGlobalMatrix A matrix containing a transform from the view to the screen
     *                           coordinates.
     * @param screenBounds The bounds of shared element in screen coordinate space. This is
     *                     the bounds of the view with the viewToGlobalMatrix applied.
     * @return A snapshot to send to the remote Activity to be reconstituted with
     * {@link #onCreateSnapshotView(android.content.Context, android.os.Parcelable)} and passed
     * into {@link #onSharedElementStart(java.util.List, java.util.List, java.util.List)} and
     * {@link #onSharedElementEnd(java.util.List, java.util.List, java.util.List)}.
     */
Creates a snapshot of a shared element to be used by the remote Activity and reconstituted
with  #onCreateSnapshotView(android.content.Context, android.os.Parcelable).

This is not called for Fragment Transitions.

@param sharedElement The shared element View to create a snapshot for.
@param viewToGlobalMatrix A matrix containing a transform from the view to the screen
coordinates.
@param screenBounds The bounds of shared element in screen coordinate space. This is
the bounds of the view with the viewToGlobalMatrix applied.
Creates a snapshot of a shared element to be used by the remote Activity and reconstituted with #onCreateSnapshotView ( android . content . Context android . os . Parcelable ) . This is not called for Fragment Transitions . @param sharedElement The shared element View to create a snapshot for . @param viewToGlobalMatrix A matrix containing a transform from the view to the screen coordinates . @param screenBounds The bounds of shared element in screen coordinate space . This is the bounds of the view with the viewToGlobalMatrix applied .
public Parcelable onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix,
            RectF screenBounds) {
        if (sharedElement instanceof ImageView) {
            ImageView imageView = ((ImageView) sharedElement);
            Drawable d = imageView.getDrawable();
            Drawable bg = imageView.getBackground();
            if (d != null && bg == null) {
                Bitmap bitmap = createDrawableBitmap(d);
                if (bitmap != null) {
                    Bundle bundle = new Bundle();
                    bundle.putParcelable(BUNDLE_SNAPSHOT_BITMAP, bitmap);
                    bundle.putString(BUNDLE_SNAPSHOT_IMAGE_SCALETYPE,
                            imageView.getScaleType().toString());
                    if (imageView.getScaleType() == ScaleType.MATRIX) {
                        Matrix matrix = imageView.getImageMatrix();
                        float[] values = new float[9];
                        matrix.getValues(values);
                        bundle.putFloatArray(BUNDLE_SNAPSHOT_IMAGE_MATRIX, values);
                    }
                    return bundle;
                }
            }
        }
        int bitmapWidth = Math.round(screenBounds.width());
        int bitmapHeight = Math.round(screenBounds.height());
        Bitmap bitmap = null;
        if (bitmapWidth > 0 && bitmapHeight > 0) {
            float scale = Math.min(1f, ((float) MAX_IMAGE_SIZE) / (bitmapWidth * bitmapHeight));
            bitmapWidth = (int) (bitmapWidth * scale);
            bitmapHeight = (int) (bitmapHeight * scale);
            if (mTempMatrix == null) {
                mTempMatrix = new Matrix();
            }
            mTempMatrix.set(viewToGlobalMatrix);
            mTempMatrix.postTranslate(-screenBounds.left, -screenBounds.top);
            mTempMatrix.postScale(scale, scale);
            bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            canvas.concat(mTempMatrix);
            sharedElement.draw(canvas);
        }
        return bitmap;
    }
public Parcelable onCaptureSharedElementSnapshot ( View sharedElement , Matrix viewToGlobalMatrix , RectF screenBounds ) { if ( sharedElement instanceof ImageView ) { ImageView imageView = ( ( ImageView ) sharedElement ) ; Drawable d = imageView . getDrawable ( ) ; Drawable bg = imageView . getBackground ( ) ; if ( d != null && bg == null ) { Bitmap bitmap = createDrawableBitmap ( d ) ; if ( bitmap != null ) { Bundle bundle = new Bundle ( ) ; bundle . putParcelable ( BUNDLE_SNAPSHOT_BITMAP , bitmap ) ; bundle . putString ( BUNDLE_SNAPSHOT_IMAGE_SCALETYPE , imageView . getScaleType ( ) . toString ( ) ) ; if ( imageView . getScaleType ( ) == ScaleType . MATRIX ) { Matrix matrix = imageView . getImageMatrix ( ) ; float [ ] values = new float [ 9 ] ; matrix . getValues ( values ) ; bundle . putFloatArray ( BUNDLE_SNAPSHOT_IMAGE_MATRIX , values ) ; } return bundle ; } } } int bitmapWidth = Math . round ( screenBounds . width ( ) ) ; int bitmapHeight = Math . round ( screenBounds . height ( ) ) ; Bitmap bitmap = null ; if ( bitmapWidth > 0 && bitmapHeight > 0 ) { float scale = Math . min ( 1f , ( ( float ) MAX_IMAGE_SIZE ) / ( bitmapWidth * bitmapHeight ) ) ; bitmapWidth = ( int ) ( bitmapWidth * scale ) ; bitmapHeight = ( int ) ( bitmapHeight * scale ) ; if ( mTempMatrix == null ) { mTempMatrix = new Matrix ( ) ; } mTempMatrix . set ( viewToGlobalMatrix ) ; mTempMatrix . postTranslate ( - screenBounds . left , - screenBounds . top ) ; mTempMatrix . postScale ( scale , scale ) ; bitmap = Bitmap . createBitmap ( bitmapWidth , bitmapHeight , Bitmap . Config . ARGB_8888 ) ; Canvas canvas = new Canvas ( bitmap ) ; canvas . concat ( mTempMatrix ) ; sharedElement . draw ( canvas ) ; } return bitmap ; }
Creates a snapshot of a shared element to be used by the remote Activity and reconstituted
 with {@link #onCreateSnapshotView(android.content.Context, android.os.Parcelable)}.
Creates a snapshot of a shared element to be used by the remote Activity and reconstituted with { @link #onCreateSnapshotView ( android . content . Context android . os . Parcelable ) } .