RTEditor/src/main/java/com/onegravity/rteditor/media/crop/ImageViewTouchBase.java
protected void center(boolean horizontal, boolean vertical) {
        if (mBitmapDisplayed.getBitmap() == null) {
            return;
        }

        Matrix m = getImageViewMatrix();

        RectF rect = new RectF(0, 0, mBitmapDisplayed.getBitmap().getWidth(),
                mBitmapDisplayed.getBitmap().getHeight());

        m.mapRect(rect);

        float height = rect.height();
        float width = rect.width();

        float deltaX = 0, deltaY = 0;

        if (vertical) {
            int viewHeight = getHeight();
            if (height < viewHeight) {
                deltaY = (viewHeight - height) / 2 - rect.top;
            } else if (rect.top > 0) {
                deltaY = -rect.top;
            } else if (rect.bottom < viewHeight) {
                deltaY = getHeight() - rect.bottom;
            }
        }

        if (horizontal) {
            int viewWidth = getWidth();
            if (width < viewWidth) {
                deltaX = (viewWidth - width) / 2 - rect.left;
            } else if (rect.left > 0) {
                deltaX = -rect.left;
            } else if (rect.right < viewWidth) {
                deltaX = viewWidth - rect.right;
            }
        }

        postTranslate(deltaX, deltaY);
        setImageMatrix(getImageViewMatrix());
    }
protected void center(boolean horizontal, boolean vertical) {
        if (mBitmapDisplayed.getBitmap() == null) {
            return;
        }

        Matrix m = getImageViewMatrix();

        RectF rect = new RectF(0, 0, mBitmapDisplayed.getBitmap().getWidth(),
                mBitmapDisplayed.getBitmap().getHeight());

        m.mapRect(rect);

        float height = rect.height();
        float width = rect.width();

        float deltaX = 0, deltaY = 0;

        if (vertical) {
            int viewHeight = getHeight();
            if (height < viewHeight) {
                deltaY = (viewHeight - height) / 2 - rect.top;
            } else if (rect.top > 0) {
                deltaY = -rect.top;
            } else if (rect.bottom < viewHeight) {
                deltaY = getHeight() - rect.bottom;
            }
        }

        if (horizontal) {
            int viewWidth = getWidth();
            if (width < viewWidth) {
                deltaX = (viewWidth - width) / 2 - rect.left;
            } else if (rect.left > 0) {
                deltaX = -rect.left;
            } else if (rect.right < viewWidth) {
                deltaX = viewWidth - rect.right;
            }
        }

        postTranslate(deltaX, deltaY);
        setImageMatrix(getImageViewMatrix());
    }
protected void center ( boolean horizontal , boolean vertical ) { if ( mBitmapDisplayed . getBitmap ( ) == null ) { return ; } Matrix m = getImageViewMatrix ( ) ; RectF rect = new RectF ( 0 , 0 , mBitmapDisplayed . getBitmap ( ) . getWidth ( ) , mBitmapDisplayed . getBitmap ( ) . getHeight ( ) ) ; m . mapRect ( rect ) ; float height = rect . height ( ) ; float width = rect . width ( ) ; float deltaX = 0 , deltaY = 0 ; if ( vertical ) { int viewHeight = getHeight ( ) ; if ( height < viewHeight ) { deltaY = ( viewHeight - height ) / 2 - rect . top ; } else if ( rect . top > 0 ) { deltaY = - rect . top ; } else if ( rect . bottom < viewHeight ) { deltaY = getHeight ( ) - rect . bottom ; } } if ( horizontal ) { int viewWidth = getWidth ( ) ; if ( width < viewWidth ) { deltaX = ( viewWidth - width ) / 2 - rect . left ; } else if ( rect . left > 0 ) { deltaX = - rect . left ; } else if ( rect . right < viewWidth ) { deltaX = viewWidth - rect . right ; } } postTranslate ( deltaX , deltaY ) ; setImageMatrix ( getImageViewMatrix ( ) ) ; }
then translate it back into view (i.e. eliminate black bars).
then translate it back into view ( i . e . eliminate black bars ) .