Java Code Examples for android.graphics.Matrix#mapRect()

The following examples show how to use android.graphics.Matrix#mapRect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GestureImageView.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
private void validate(RectF curImageRect,Matrix curImageMatrix, PointF outDelta)
{	
	float  deltaX= 0, deltaY = 0;
	RectF imageRect = new RectF(curImageRect);
	curImageMatrix.mapRect(imageRect);		
	
	if (imageRect.height() <= _viewRect.height())
		deltaY = (_viewRect.height() - imageRect.height()) / 2 - imageRect.top;
    else if (imageRect.top > 0) 
    	deltaY = -imageRect.top;
    else if (imageRect.bottom < _viewRect.height()) 
    	deltaY = _viewRect.height() - imageRect.bottom;		
	
	
	if (imageRect.width() <= _viewRect.width())	
		deltaX = (_viewRect.width() - imageRect.width()) / 2 - imageRect.left;		
    else if (imageRect.left > 0)	    
    	deltaX = -imageRect.left;
    else if (imageRect.right < _viewRect.width())	    
    	deltaX = _viewRect.width() - imageRect.right;
    
	outDelta.offset(deltaX, deltaY);
}
 
Example 2
Source File: ImageViewTouchBase.java    From LockDemo with Apache License 2.0 6 votes vote down vote up
protected void center() {
    final Bitmap bitmap = bitmapDisplayed.getBitmap();
    if (bitmap == null) {
        return;
    }
    Matrix m = getImageViewMatrix();

    RectF rect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
    m.mapRect(rect);

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

    float deltaX = 0, deltaY = 0;

    deltaY = centerVertical(rect, height, deltaY);
    deltaX = centerHorizontal(rect, width, deltaX);

    postTranslate(deltaX, deltaY);
    setImageMatrix(getImageViewMatrix());
}
 
Example 3
Source File: CustomizePlayerView.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private static void applyTextureViewRotation(TextureView textureView, int textureViewRotation) {
    float textureViewWidth = textureView.getWidth();
    float textureViewHeight = textureView.getHeight();
    if (textureViewWidth == 0 || textureViewHeight == 0 || textureViewRotation == 0) {
        textureView.setTransform(null);
    } else {
        Matrix transformMatrix = new Matrix();
        float pivotX = textureViewWidth / 2;
        float pivotY = textureViewHeight / 2;
        transformMatrix.postRotate(textureViewRotation, pivotX, pivotY);

        // After rotation, scale the rotated texture to fit the TextureView size.
        RectF originalTextureRect = new RectF(0, 0, textureViewWidth, textureViewHeight);
        RectF rotatedTextureRect = new RectF();
        transformMatrix.mapRect(rotatedTextureRect, originalTextureRect);
        transformMatrix.postScale(
                textureViewWidth / rotatedTextureRect.width(),
                textureViewHeight / rotatedTextureRect.height(),
                pivotX,
                pivotY);
        textureView.setTransform(transformMatrix);
    }
}
 
Example 4
Source File: PhotoViewAttacher.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that maps the supplied Matrix to the current Drawable
 *
 * @param matrix - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle
 */
private RectF getDisplayRect(Matrix matrix) {
    ImageView imageView = getImageView();

    if (null != imageView) {
        Drawable d = imageView.getDrawable();
        if (null != d) {
            mDisplayRect.set(0, 0, d.getIntrinsicWidth(),
                    d.getIntrinsicHeight());
            matrix.mapRect(mDisplayRect);
            return mDisplayRect;
        }
    }
    return null;
}
 
Example 5
Source File: OBControl.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
public RectF convertRectFromControl (RectF r, OBControl c)
{
    Matrix m = matrixToConvertPointFromControl(c);
    RectF nr = new RectF();
    m.mapRect(nr, r);
    return nr;
}
 
Example 6
Source File: PhotoViewAttacher.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that maps the supplied Matrix to the current Drawable
 *
 * @param matrix - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle
 */
private RectF getDisplayRect(Matrix matrix) {
    ImageView imageView = getImageView();

    if (null != imageView) {
        Drawable d = imageView.getDrawable();
        if (null != d) {
            mDisplayRect.set(0, 0, d.getIntrinsicWidth(),
                    d.getIntrinsicHeight());
            matrix.mapRect(mDisplayRect);
            return mDisplayRect;
        }
    }
    return null;
}
 
Example 7
Source File: PhotoViewAttacher.java    From ImagePicker with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that maps the supplied Matrix to the current Drawable
 *
 * @param matrix - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle
 */
private RectF getDisplayRect(Matrix matrix)
{
    Drawable d = mImageView.getDrawable();
    if (d != null)
    {
        mDisplayRect.set(0, 0, d.getIntrinsicWidth(),
                d.getIntrinsicHeight());
        matrix.mapRect(mDisplayRect);
        return mDisplayRect;
    }
    return null;
}
 
Example 8
Source File: PhotoViewAttacher.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that maps the supplied Matrix to the current Drawable
 * 
 * @param matrix
 *            - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle
 */
private RectF getDisplayRect(Matrix matrix) {
	ImageView imageView = getImageView();

	if (null != imageView) {
		Drawable d = imageView.getDrawable();
		if (null != d) {
			mDisplayRect.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
			matrix.mapRect(mDisplayRect);
			return mDisplayRect;
		}
	}
	return null;
}
 
Example 9
Source File: Transformer.java    From JNChartDemo with Apache License 2.0 5 votes vote down vote up
/**
 * transforms multiple rects with all matrices
 *
 * @param rects
 */
public void rectValuesToPixel(List<RectF> rects) {

    Matrix m = getValueToPixelMatrix();

    for (int i = 0; i < rects.size(); i++)
        m.mapRect(rects.get(i));
}
 
Example 10
Source File: Transformer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * transforms multiple rects with all matrices
 *
 * @param rects
 */
public void rectValuesToPixel(List<RectF> rects) {

    Matrix m = getValueToPixelMatrix();

    for (int i = 0; i < rects.size(); i++)
        m.mapRect(rects.get(i));
}
 
Example 11
Source File: FullImageView.java    From Moment with GNU General Public License v3.0 5 votes vote down vote up
private RectF getMatrixRectF() {
    Matrix matrix = imageMatrix;
    RectF rect = new RectF();
    Drawable d = getDrawable();
    if (null != d) {
        rect.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        matrix.mapRect(rect);
    }
    return rect;
}
 
Example 12
Source File: ZoomImageView.java    From HttpRequest with Apache License 2.0 5 votes vote down vote up
/**
  * 根据当前图片的Matrix获得图片的范围
  * @author leibing
  * @createTime 2017/6/5
  * @lastModify 2017/6/5
  * @param
  * @return
  */
public RectF getMatrixRectF()
{
	Matrix matrix = mScaleMatrix;
	RectF rect = new RectF();
	Drawable d = getDrawable();
	if (null != d) {
		rect.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
		matrix.mapRect(rect);
	}
	return rect;
}
 
Example 13
Source File: ZoomImageView.java    From ZoomImageView with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that maps the supplied Matrix to the current Drawable
 * 
 * @param matrix
 *            - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle
 */
private RectF getDisplayRect(Matrix matrix) {
    Drawable d = getDrawable();
    if (null != d) {
        displayRect.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        matrix.mapRect(displayRect);
        return displayRect;
    }

    return null;
}
 
Example 14
Source File: Transformer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * transforms multiple rects with all matrices
 *
 * @param rects
 */
public void rectValuesToPixel(List<RectF> rects) {

    Matrix m = getValueToPixelMatrix();

    for (int i = 0; i < rects.size(); i++)
        m.mapRect(rects.get(i));
}
 
Example 15
Source File: PhotoViewAttacher.java    From MNImageBrowser with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Helper method that maps the supplied Matrix to the current Drawable
 *
 * @param matrix - Matrix to map Drawable against
 * @return RectF - Displayed Rectangle
 */
private RectF getDisplayRect(Matrix matrix) {
    Drawable d = mImageView.getDrawable();
    if (d != null) {
        mDisplayRect.set(0, 0, d.getIntrinsicWidth(),
                d.getIntrinsicHeight());
        matrix.mapRect(mDisplayRect);
        return mDisplayRect;
    }
    return null;
}
 
Example 16
Source File: PageTreeNode.java    From Mupdf with Apache License 2.0 5 votes vote down vote up
private RectF evaluatePageSliceBounds(RectF localPageSliceBounds, PageTreeNode parent) {
    if (parent == null) {
        return localPageSliceBounds;
    }
    final Matrix matrix = new Matrix();
    matrix.postScale(parent.pageSliceBounds.width(), parent.pageSliceBounds.height());
    matrix.postTranslate(parent.pageSliceBounds.left, parent.pageSliceBounds.top);
    final RectF sliceBounds = new RectF();
    matrix.mapRect(sliceBounds, localPageSliceBounds);
    return sliceBounds;
}
 
Example 17
Source File: FaceDetectorUtil.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
public FaceParsed camera1Parse(Camera.Face face, View view, PointF scale, int rotation,
    boolean isFrontCamera) {
  //Parse face
  RectF rect = new RectF(face.rect);
  Matrix matrix = new Matrix();
  matrix.setScale(isFrontCamera ? -1 : 1, 1);
  matrix.postRotate(rotation);
  matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);
  matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);
  matrix.mapRect(rect);
  return getFace(rect, scale, view);
}
 
Example 18
Source File: ImageViewTouchBase.java    From FlickableView with Apache License 2.0 4 votes vote down vote up
protected RectF getBitmapRect(Matrix supportMatrix) {
    Matrix m = getImageViewMatrix(supportMatrix);
    m.mapRect(mBitmapRectTmp, mBitmapRect);
    return mBitmapRectTmp;
}
 
Example 19
Source File: PinchImageView.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 双击后放大或者缩小
 * <p>
 * 将图片缩放比例缩放到nextScale指定的值.
 * 但nextScale值不能大于最大缩放值不能小于fit center情况下的缩放值.
 * 将双击的点尽量移动到控件中心.
 *
 * @param x 双击的点
 * @param y 双击的点
 * @see #calculateNextScale(float, float)
 * @see #getMaxScale()
 */
private void doubleTap(float x, float y) {
    if (!isReady()) {
        return;
    }
    //获取第一层变换矩阵
    Matrix innerMatrix = MathUtils.matrixTake();
    getInnerMatrix(innerMatrix);
    //当前总的缩放比例
    float innerScale = MathUtils.getMatrixScale(innerMatrix)[0];
    float outerScale = MathUtils.getMatrixScale(mOuterMatrix)[0];
    float currentScale = innerScale * outerScale;
    //控件大小
    float displayWidth = getWidth();
    float displayHeight = getHeight();
    //最大放大大小
    float maxScale = getMaxScale();
    //接下来要放大的大小
    float nextScale = calculateNextScale(innerScale, outerScale);
    //如果接下来放大大于最大值或者小于fit center值,则取边界
    if (nextScale > maxScale) {
        nextScale = maxScale;
    }
    if (nextScale < innerScale) {
        nextScale = innerScale;
    }
    //开始计算缩放动画的结果矩阵
    Matrix animEnd = MathUtils.matrixTake(mOuterMatrix);
    //计算还需缩放的倍数
    animEnd.postScale(nextScale / currentScale, nextScale / currentScale, x, y);
    //将放大点移动到控件中心
    animEnd.postTranslate(displayWidth / 2f - x, displayHeight / 2f - y);
    //得到放大之后的图片方框
    Matrix testMatrix = MathUtils.matrixTake(innerMatrix);
    testMatrix.postConcat(animEnd);
    RectF testBound = MathUtils.rectFTake(0, 0, getDrawable().getIntrinsicWidth(), getDrawable().getIntrinsicHeight());
    testMatrix.mapRect(testBound);
    //修正位置
    float postX = 0;
    float postY = 0;
    if (testBound.right - testBound.left < displayWidth) {
        postX = displayWidth / 2f - (testBound.right + testBound.left) / 2f;
    } else if (testBound.left > 0) {
        postX = -testBound.left;
    } else if (testBound.right < displayWidth) {
        postX = displayWidth - testBound.right;
    }
    if (testBound.bottom - testBound.top < displayHeight) {
        postY = displayHeight / 2f - (testBound.bottom + testBound.top) / 2f;
    } else if (testBound.top > 0) {
        postY = -testBound.top;
    } else if (testBound.bottom < displayHeight) {
        postY = displayHeight - testBound.bottom;
    }
    //应用修正位置
    animEnd.postTranslate(postX, postY);
    //清理当前可能正在执行的动画
    cancelAllAnimator();
    //启动矩阵动画
    mScaleAnimator = new ScaleAnimator(mOuterMatrix, animEnd);
    mScaleAnimator.start();
    //清理临时变量
    MathUtils.rectFGiven(testBound);
    MathUtils.matrixGiven(testMatrix);
    MathUtils.matrixGiven(animEnd);
    MathUtils.matrixGiven(innerMatrix);
}
 
Example 20
Source File: ImageViewTouchBase.java    From reader with MIT License 4 votes vote down vote up
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());
}