Example usage for android.graphics Matrix mapPoints

List of usage examples for android.graphics Matrix mapPoints

Introduction

In this page you can find the example usage for android.graphics Matrix mapPoints.

Prototype

public void mapPoints(float[] pts) 

Source Link

Document

Apply this matrix to the array of 2D points, and write the transformed points back into the array

Usage

From source file:com.example.linhdq.test.documents.creation.crop.CropImageActivity.java

@OnClick(R.id.item_save)
void onSaveClicked() {
    if (!mCropData.isPresent() || mSaving || (mCrop == null)) {
        return;//from   w w  w  .j av  a  2 s. c  o m
    }
    mSaving = true;

    Util.startBackgroundJob(this, null, getText(R.string.cropping_image).toString(), new Runnable() {
        public void run() {
            try {
                float scale = 1f / mCropData.get().getScaleResult().getScaleFactor();
                Matrix scaleMatrix = new Matrix();
                scaleMatrix.setScale(scale, scale);

                final float[] trapezoid = mCrop.getTrapezoid();
                final RectF perspectiveCorrectedBoundingRect = new RectF(
                        mCrop.getPerspectiveCorrectedBoundingRect());
                scaleMatrix.mapRect(perspectiveCorrectedBoundingRect);
                Box bb = new Box((int) perspectiveCorrectedBoundingRect.left,
                        (int) perspectiveCorrectedBoundingRect.top,
                        (int) perspectiveCorrectedBoundingRect.width(),
                        (int) perspectiveCorrectedBoundingRect.height());

                Pix pix8 = Convert.convertTo8(mPix);
                mPix.recycle();

                Pix croppedPix = Clip.clipRectangle2(pix8, bb);
                if (croppedPix == null) {
                    throw new IllegalStateException();
                }
                pix8.recycle();

                scaleMatrix.postTranslate(-bb.getX(), -bb.getY());
                scaleMatrix.mapPoints(trapezoid);

                final float[] dest = new float[] { 0, 0, bb.getWidth(), 0, bb.getWidth(), bb.getHeight(), 0,
                        bb.getHeight() };
                Pix bilinear = Projective.projectiveTransform(croppedPix, dest, trapezoid);
                if (bilinear == null) {
                    bilinear = croppedPix;
                } else {
                    croppedPix.recycle();
                }

                if (mRotation != 0 && mRotation != 4) {
                    Pix rotatedPix = Rotate.rotateOrth(bilinear, mRotation);
                    bilinear.recycle();
                    bilinear = rotatedPix;
                }
                if (bilinear == null) {
                    throw new IllegalStateException();
                }
                Intent result = new Intent();
                OCR.savePixToCacheDir(CropImageActivity.this, bilinear.copy());
                result.putExtra(DocumentGridActivity.EXTRA_NATIVE_PIX, bilinear.getNativePix());
                setResult(RESULT_OK, result);
            } catch (IllegalStateException e) {
                setResult(RESULT_CANCELED);
            } finally {
                finish();
            }
        }
    }, mHandler);

}

From source file:com.android.launcher2.Workspace.java

void mapPointFromSelfToChild(View v, float[] xy, Matrix cachedInverseMatrix) {
    if (cachedInverseMatrix == null) {
        v.getMatrix().invert(mTempInverseMatrix);
        cachedInverseMatrix = mTempInverseMatrix;
    }/* www .ja v a2 s .  c o m*/
    int scrollX = getScrollX();
    if (mNextPage != INVALID_PAGE) {
        scrollX = mScroller.getFinalX();
    }
    xy[0] = xy[0] + scrollX - v.getLeft();
    xy[1] = xy[1] + getScrollY() - v.getTop();
    cachedInverseMatrix.mapPoints(xy);
}