Matrix reset - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Matrix reset method.

This code example shows how to use the following methods:mapRect, postScale, postTranslate, preTranslate, reset
 
        // use a rectangle at 0,0 to make sure we don't run into issues with scaling 
        r.set(0, 0, w, h);
 
        final Matrix m = mTempMatrix;
        m.reset();
        transformMatrix(m, view);
        mTempMatrix.mapRect(r);
 
        r.offset(view.getLeft(), view.getTop());
 
        // Straighten coords if rotations flipped them 
        if (r.right < r.left) {
            final float f = r.right;
            r.right = r.left;
            r.left = f;
        } 
        if (r.bottom < r.top) {
            final float f = r.top;
            r.top = r.bottom;

8
CodeRank
This code example shows how to use the following methods:mapRect, postScale, postTranslate, reset
 
        // use a rectangle at 0,0 to make sure we don't run into issues with scaling 
        r.set(0, 0, w, h);
 
        final Matrix m = mTempMatrix;
        m.reset();
        transformMatrix(m, view);
        mTempMatrix.mapRect(r);
 
        r.offset(view.getLeft(), view.getTop());
 
        // Straighten coords if rotations flipped them 
        if (r.right < r.left) {
            final float f = r.right;
            r.right = r.left;
            r.left = f;
        } 
        if (r.bottom < r.top) {
            final float f = r.top;
            r.top = r.bottom;

8
CodeRank
This code example shows how to use the following methods:postConcat, postRotate, reset
	} 
 
	private void computeBaseMatrix() 
	{ 
		Drawable d = imageView.getDrawable();
		baseMatrix.reset();
 
		if (d != null) {
			// The base matrix is the matrix that displays the entire image bitmap. 
			// It orients the image when orientation is set and scales in X and Y independently,  
			// so that src matches dst exactly. 
			// This may change the aspect ratio of the src. 
			Rect r = new Rect();
			getDrawingRect(r);
			int intrinsicWidth = d.getIntrinsicWidth();
			int intrinsicHeight = d.getIntrinsicHeight();
			int dwidth = intrinsicWidth;
			int dheight = intrinsicHeight;
 
			if (orientation > 0) {

8
CodeRank
This code example shows how to use the following methods:mapRect, postRotate, postScale, postTranslate, reset
     * @see android.widget.ImageView#setImageBitmap(android.graphics.Bitmap) 
     */ 
    @Override 
    public void setImageBitmap(Bitmap bitmap)
    { 
        Matrix matrix = new Matrix();
        matrix.reset();
        // apply the camera display characteristics. First mirror the image... 
        if (mbMirror)
        { 
            matrix.postScale(-1f, 1f);
        } 
        // then rotate it... 
        matrix.postRotate(mnDisplayOrientation);
        /** 
         * Math is hard!  
         *         -- Barbie 
         *  
         * We could calculate the matrix that will map the rotated and possibly 
         * mirrored image to the display, but it is much easier to compose a 

8
CodeRank
This code example shows how to use the following methods:mapPoints, postTranslate, preTranslate, reset
	private Matrix mMatrix = new Matrix();
	private Camera mCamera = new Camera();
	private float[] mTempFloat2 = new float[2];
 
	protected float getOffsetXForRotation(float degrees, int width, int height) {
		mMatrix.reset();
		mCamera.save();
		mCamera.rotateY(Math.abs(degrees));
		mCamera.getMatrix(mMatrix);
		mCamera.restore();
 
		mMatrix.preTranslate(-width * 0.5f, -height * 0.5f);
		mMatrix.postTranslate(width * 0.5f, height * 0.5f);
		mTempFloat2[0] = width;
		mTempFloat2[1] = height;
		mMatrix.mapPoints(mTempFloat2);
		return (width - mTempFloat2[0]) * (degrees > 0.0f ? 1.0f : -1.0f);
	} 
 
	protected void animateFade(View left, View right, float positionOffset) {
		if (left != null) {
7
CodeRank
This code example shows how to use the following methods:postTranslate, reset, setRectToRect, setScale, setTranslate
 
        if (bitmap == null) {
            return null; 
        } 
 
        mMatrix.reset();
 
        final int bWidth = bitmap.getWidth();
        final int bHeight = bitmap.getHeight();
 
        switch (mScaleType) {
 
            case CENTER_CROP: {
                // Center and scale the bitmap so that it entirely fills the 
                // given space. The bitmap ratio remains unchanged 
                float scale;
                float dx = 0, dy = 0;
 
                if (bWidth * mHeight > mWidth * bHeight) {
                    scale = (float) mHeight / (float) bHeight;

7
CodeRank
This code example shows how to use the following methods:postScale, postTranslate, reset
        public void setDrawable(Drawable d) {
            mDrawable = d;
             
            float sizeX = mDrawable.getIntrinsicWidth()/2;
            float sizeY = mDrawable.getIntrinsicHeight()/2;
            mMatrix.reset();
            mMatrix.postTranslate(-sizeX, -sizeY);
            mMatrix.postScale(mScale, mScale);
            mMatrix.postTranslate(mPosX, mPosY);
        } 
         
        @Override 
        public boolean onTouchEvent(MotionEvent event) {
            mDetector.onTouchEvent(event);
             
            // Handling single finger pan 
            if (!mDetector.isInProgress()) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        mLastX = event.getX();
7
CodeRank
This code example shows how to use the following methods:postConcat, postScale, postTranslate, reset
        float viewWidth = getWidth();
        float viewHeight = getHeight();
 
        float w = bitmap.getWidth();
        float h = bitmap.getHeight();
        matrix.reset();
 
        // We limit up-scaling to 2x otherwise the result may look bad if it's 
        // a small icon. 
        float widthScale = Math.min(viewWidth / w, 2.0f);
        float heightScale = Math.min(viewHeight / h, 2.0f);
        float scale = Math.min(widthScale, heightScale);
 
        matrix.postConcat(bitmap.getRotateMatrix());
        matrix.postScale(scale, scale);
 
        matrix.postTranslate((viewWidth - w * scale) / 2F, (viewHeight - h * scale) / 2F);
    } 
 
    // Combine the base matrix and the supp matrix to make the final matrix. 

7
CodeRank
This code example shows how to use the following methods:postScale, postTranslate, reset
                float diffY = centerY - mPosY;
                diffX = diffX*scale - diffX;
                diffY = diffY*scale - diffY;
                mPosX -= diffX;
                mPosY -= diffY;
                mMatrix.reset();
                mMatrix.postTranslate(-sizeX, -sizeY);
                mMatrix.postScale(mScale, mScale);
                mMatrix.postTranslate(mPosX, mPosY);
                                 
                invalidate();
 
                return true; 
            } 
 
            public boolean onScaleBegin(ScaleGestureDetector detector) {
                return true; 
            } 
 
            public void onScaleEnd(ScaleGestureDetector detector) {
7
CodeRank
This code example shows how to use the following methods:mapRect, postTranslate, reset
            final float h = view.getHeight();
 
            r.set(0, 0, w, h);
 
            final Matrix m = mTempMatrix;
            m.reset();
            transformMatrix(m, view);
            mTempMatrix.mapRect(r);
 
            r.offset(view.getLeft(), view.getTop());
        } 
 
        private void transformMatrix(Matrix m, View view) {
            m.postTranslate(mTranslationX, mTranslationY);
        } 
 
        private void invalidateAfterUpdate() { 
            View view = mViewRef.get();
            if (view == null || view.getParent() == null)
                return; 
7
CodeRank

Related Matrix reset Questions & Answers:

reset Method Overview
Set the matrix to identity
See Code Examples for other Android Matrix Methods: