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

The following examples show how to use android.graphics.Matrix#getValues() . 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: ImageActivity.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private void c()
{
    float f1 = q.width();
    Matrix matrix = e.getImageMatrix();
    float af[] = new float[9];
    matrix.getValues(af);
    float f2 = af[2];
    float f3 = af[5];
    float f4 = af[0];
    float f5 = (float)o / f1;
    int i1 = (int)(((float)q.left - f2) / f4);
    int j1 = (int)(((float)q.top - f3) / f4);
    Matrix matrix1 = new Matrix();
    matrix1.set(matrix);
    matrix1.postScale(f5, f5);
    int k1 = (int)(650F / f4);
    int l1 = Math.min(s.getWidth() - i1, k1);
    int i2 = Math.min(s.getHeight() - j1, k1);
    Bitmap bitmap = Bitmap.createBitmap(s, i1, j1, l1, i2, matrix1, true);
    Bitmap bitmap1 = Bitmap.createBitmap(bitmap, 0, 0, o, p);
    bitmap.recycle();
    a(bitmap1);
}
 
Example 2
Source File: AndroidGraphicsBridge.java    From CrossMobile with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public CGAffineTransform nativeToTarget(Matrix from, CGAffineTransform to) {
    float[] matrix = new float[9];
    from.getValues(matrix);
    if (to == null)
        to = new CGAffineTransform(matrix[0], matrix[3], matrix[1], matrix[4], matrix[2], matrix[5]);
    else {
        to.setA(matrix[0]);
        to.setB(matrix[3]);
        to.setC(matrix[1]);
        to.setD(matrix[4]);
        to.setTx(matrix[2]);
        to.setTy(matrix[5]);
    }
    return to;
}
 
Example 3
Source File: GLMatrix.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static float[] LoadGraphicsMatrix(Matrix matrix) {
    float m[] = new float[16];
    float v[] = new float[9];
    matrix.getValues(v);

    m[0] = v[Matrix.MSCALE_X]; //m.a;
    m[1] = v[Matrix.MSKEW_X]; //m.b;
    m[2] = 0.0f;
    m[3] = 0.0f;

    m[4] = v[Matrix.MSKEW_Y]; //m.c;
    m[5] = v[Matrix.MSCALE_Y]; //m.d;
    m[6] = 0.0f;
    m[7] = 0.0f;

    m[8] = 0.0f;
    m[9] = 0.0f;
    m[10] = 1.0f;
    m[11] = 0.0f;

    m[12] = v[Matrix.MTRANS_X]; //m.tx;
    m[13] = v[Matrix.MTRANS_Y]; //m.ty;
    m[14] = 0.0f;
    m[15] = 1.0f;

    return m;
}
 
Example 4
Source File: SelectableRoundedImageView.java    From sealtalk-android with MIT License 5 votes vote down vote up
private void adjustCanvasForBorder(Canvas canvas) {
    Matrix canvasMatrix = canvas.getMatrix();
    final float[] values = new float[9];
    canvasMatrix.getValues(values);

    final float scaleFactorX = values[0];
    final float scaleFactorY = values[4];
    final float translateX = values[2];
    final float translateY = values[5];

    final float newScaleX = mBounds.width()
            / (mBounds.width() + mBorderWidth + mBorderWidth);
    final float newScaleY = mBounds.height()
            / (mBounds.height() + mBorderWidth + mBorderWidth);

    canvas.scale(newScaleX, newScaleY);
    if (ScaleType.FIT_START == mScaleType || ScaleType.FIT_END == mScaleType
            || ScaleType.FIT_XY == mScaleType || ScaleType.FIT_CENTER == mScaleType
            || ScaleType.CENTER_INSIDE == mScaleType || ScaleType.MATRIX == mScaleType) {
        canvas.translate(mBorderWidth, mBorderWidth);
    } else if (ScaleType.CENTER == mScaleType || ScaleType.CENTER_CROP == mScaleType) {
        // First, make translate values to 0
        canvas.translate(
                -translateX / (newScaleX * scaleFactorX), 
                -translateY / (newScaleY * scaleFactorY));
        // Then, set the final translate values.
        canvas.translate(-(mBounds.left - mBorderWidth), -(mBounds.top - mBorderWidth));
    } 
}
 
Example 5
Source File: MatrixEvaluator.java    From scene with Apache License 2.0 5 votes vote down vote up
@Override
public Matrix evaluate(float fraction, Matrix startValue, Matrix endValue) {
    startValue.getValues(mTempStartValues);
    endValue.getValues(mTempEndValues);
    for (int i = 0; i < 9; i++) {
        float diff = mTempEndValues[i] - mTempStartValues[i];
        mTempEndValues[i] = mTempStartValues[i] + (fraction * diff);
    }
    mTempMatrix.setValues(mTempEndValues);

    return mTempMatrix;
}
 
Example 6
Source File: ViewPortHandler.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * limits the maximum scale and X translation of the given matrix
 *
 * @param matrix
 */
public void limitTransAndScale(Matrix matrix, RectF content) {

    matrix.getValues(matrixBuffer);

    float curTransX = matrixBuffer[Matrix.MTRANS_X];
    float curScaleX = matrixBuffer[Matrix.MSCALE_X];

    float curTransY = matrixBuffer[Matrix.MTRANS_Y];
    float curScaleY = matrixBuffer[Matrix.MSCALE_Y];

    // min scale-x is 1f
    mScaleX = Math.min(Math.max(mMinScaleX, curScaleX), mMaxScaleX);

    // min scale-y is 1f
    mScaleY = Math.min(Math.max(mMinScaleY, curScaleY), mMaxScaleY);

    float width = 0f;
    float height = 0f;

    if (content != null) {
        width = content.width();
        height = content.height();
    }

    float maxTransX = -width * (mScaleX - 1f);
    mTransX = Math.min(Math.max(curTransX, maxTransX - mTransOffsetX), mTransOffsetX);

    float maxTransY = height * (mScaleY - 1f);
    mTransY = Math.max(Math.min(curTransY, maxTransY + mTransOffsetY), -mTransOffsetY);

    matrixBuffer[Matrix.MTRANS_X] = mTransX;
    matrixBuffer[Matrix.MSCALE_X] = mScaleX;

    matrixBuffer[Matrix.MTRANS_Y] = mTransY;
    matrixBuffer[Matrix.MSCALE_Y] = mScaleY;

    matrix.setValues(matrixBuffer);
}
 
Example 7
Source File: PinchImageView.java    From ImagePicker with Apache License 2.0 5 votes vote down vote up
/**
 * 获取矩阵的缩放值
 *
 * @param matrix 要计算的矩阵
 * @return float[]{scaleX, scaleY}
 */
public static float[] getMatrixScale(Matrix matrix) {
    if (matrix != null) {
        float[] value = new float[9];
        matrix.getValues(value);
        return new float[]{value[0], value[4]};
    } else {
        return new float[2];
    }
}
 
Example 8
Source File: ScaleImageView.java    From ImageChoose with MIT License 4 votes vote down vote up
protected float getValue(Matrix matrix, int whichValue) {
    matrix.getValues(mMatrixValues);
    return mMatrixValues[whichValue];
}
 
Example 9
Source File: ImageViewTouchBase.java    From Pi-Locker with GNU General Public License v2.0 4 votes vote down vote up
protected float getValue(Matrix matrix, int whichValue) {

        matrix.getValues(mMatrixValues);
        return mMatrixValues[whichValue];
    }
 
Example 10
Source File: ImageViewTouchBase.java    From LockDemo with Apache License 2.0 4 votes vote down vote up
protected float getValue(Matrix matrix, int whichValue) {
    matrix.getValues(matrixValues);
    return matrixValues[whichValue];
}
 
Example 11
Source File: AnimationMatrix.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private AnimationMatrix(@NonNull Matrix undo, @NonNull Runnable invalidate) {
  this.invalidate = invalidate;
  this.canAnimate = true;
  undo.getValues(undoValues);
}
 
Example 12
Source File: ImageViewUtil.java    From PhotoViewCropper with Apache License 2.0 4 votes vote down vote up
public static float getXTran(Matrix matrix){
    float[] f = new float[9];
    matrix.getValues(f);
    return f[Matrix.MTRANS_X];
}
 
Example 13
Source File: MatrixActivity.java    From AndroidDemo with Apache License 2.0 4 votes vote down vote up
public boolean onTouch(View v, MotionEvent e) {
		if (e.getAction() == MotionEvent.ACTION_UP) {
			Matrix matrix = new Matrix();

//			// 1. 平移
//			matrix.postTranslate(view.getImageBitmap().getWidth(), view.getImageBitmap().getHeight());
//			// 在x方向平移view.getImageBitmap().getWidth(),在y轴方向view.getImageBitmap().getHeight()
//			view.setImageMatrix(matrix);

//			// 2. 旋转(围绕图像的中心点)
//			matrix.setRotate(45f, view.getImageBitmap().getWidth() / 2f, view.getImageBitmap().getHeight() / 2f);
//			// 做下面的平移变换,纯粹是为了让变换后的图像和原图像不重叠
//			matrix.postTranslate(view.getImageBitmap().getWidth() * 1.5f, 0f);
//			view.setImageMatrix(matrix);


			// 3. 旋转(围绕坐标原点) + 平移(效果同2)
//			matrix.setRotate(45f);
//			matrix.preTranslate(-1f * view.getImageBitmap().getWidth() / 2f, -1f * view.getImageBitmap().getHeight() / 2f);
//			matrix.postTranslate((float)view.getImageBitmap().getWidth() / 2f, (float)view.getImageBitmap().getHeight() / 2f);
//			// 做下面的平移变换,纯粹是为了让变换后的图像和原图像不重叠
//			matrix.postTranslate((float)view.getImageBitmap().getWidth() * 1.5f, 0f);
//			view.setImageMatrix(matrix);


			// 4. 缩放
//			matrix.setScale(2f, 2f);
//			// 做下面的平移变换,纯粹是为了让变换后的图像和原图像不重叠
//			matrix.postTranslate(view.getImageBitmap().getWidth(), view.getImageBitmap().getHeight());
//			view.setImageMatrix(matrix);


			// 5. 错切 - 水平
//			matrix.setSkew(1f, 0f);
//			// 做下面的平移变换,纯粹是为了让变换后的图像和原图像不重叠
//			matrix.postTranslate(view.getImageBitmap().getWidth(), 0f);
//			view.setImageMatrix(matrix);


//			// 6. 错切 - 垂直
//			matrix.setSkew(0f, 0.5f);
//			// 做下面的平移变换,纯粹是为了让变换后的图像和原图像不重叠
//			matrix.postTranslate(0f, view.getImageBitmap().getHeight());
//			view.setImageMatrix(matrix);


//			7. 错切 - 水平 + 垂直
//			matrix.setSkew(0.5f, 0.5f);
//			// 做下面的平移变换,纯粹是为了让变换后的图像和原图像不重叠
//			matrix.postTranslate(0f, view.getImageBitmap().getHeight());
//			view.setImageMatrix(matrix);

//			// 8. 对称 (水平对称)
			float matrix_values[] = {1f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, 1f};
			matrix.setValues(matrix_values);
			// 做下面的平移变换,纯粹是为了让变换后的图像和原图像不重叠
			matrix.postTranslate(0f, view.getImageBitmap().getHeight() * 2f);
			view.setImageMatrix(matrix);

//			// 9. 对称 - 垂直
//			float matrix_values[] = {-1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f};
//			matrix.setValues(matrix_values);
//
//			// 做下面的平移变换,纯粹是为了让变换后的图像和原图像不重叠
//			matrix.postTranslate(view.getImageBitmap().getWidth() * 2f, 0f);
//			view.setImageMatrix(matrix);

//			// 10. 对称(对称轴为直线y = x)
//			float matrix_values[] = {0f, -1f, 0f, -1f, 0f, 0f, 0f, 0f, 1f};
//			matrix.setValues(matrix_values);
//
//			// 做下面的平移变换,纯粹是为了让变换后的图像和原图像不重叠
//			matrix.postTranslate(view.getImageBitmap().getHeight() + view.getImageBitmap().getWidth(),
//					view.getImageBitmap().getHeight() + view.getImageBitmap().getWidth());
//			view.setImageMatrix(matrix);

			// 下面的代码是为了查看matrix中的元素
			float[] matrixValues = new float[9];
			matrix.getValues(matrixValues);
			for(int i = 0; i < 3; ++i)
			{
				String temp = new String();
				for(int j = 0; j < 3; ++j)
				{
					temp += matrixValues[3 * i + j ] + "\t";
				}
				Log.e(TAG, temp);
			}

			view.invalidate();
		}
		return true;
	}
 
Example 14
Source File: PhotoViewAttacher.java    From BigApp_Discuz_Android with Apache License 2.0 2 votes vote down vote up
/**
 * Helper method that 'unpacks' a Matrix and returns the required value
 *
 * @param matrix     - Matrix to unpack
 * @param whichValue - Which value from Matrix.M* to return
 * @return float - returned value
 */
private float getValue(Matrix matrix, int whichValue) {
    matrix.getValues(mMatrixValues);
    return mMatrixValues[whichValue];
}
 
Example 15
Source File: PhotoViewAttacher.java    From AndroidPickPhotoDialog with Apache License 2.0 2 votes vote down vote up
/**
 * Helper method that 'unpacks' a Matrix and returns the required value
 *
 * @param matrix     - Matrix to unpack
 * @param whichValue - Which value from Matrix.M* to return
 * @return float - returned value
 */
private float getValue(Matrix matrix, int whichValue) {
    matrix.getValues(mMatrixValues);
    return mMatrixValues[whichValue];
}
 
Example 16
Source File: TransformImageView.java    From EasyPhotos with Apache License 2.0 2 votes vote down vote up
/**
 * This method returns Matrix value for given index.
 *
 * @param matrix     - valid Matrix object
 * @param valueIndex - index of needed value. See {@link Matrix#MSCALE_X} and others.
 * @return - matrix value for index
 */
protected float getMatrixValue(@NonNull Matrix matrix, @IntRange(from = 0, to = MATRIX_VALUES_COUNT) int valueIndex) {
    matrix.getValues(mMatrixValues);
    return mMatrixValues[valueIndex];
}
 
Example 17
Source File: PhotoViewAttacher.java    From Tweetin with Apache License 2.0 2 votes vote down vote up
/**
 * Helper method that 'unpacks' a Matrix and returns the required value
 *
 * @param matrix     - Matrix to unpack
 * @param whichValue - Which value from Matrix.M* to return
 * @return float - returned value
 */
private float getValue(Matrix matrix, int whichValue) {
    matrix.getValues(mMatrixValues);
    return mMatrixValues[whichValue];
}
 
Example 18
Source File: PhotoViewAttacher.java    From UltimateAndroid with Apache License 2.0 2 votes vote down vote up
/**
 * Helper method that 'unpacks' a Matrix and returns the required value
 *
 * @param matrix     - Matrix to unpack
 * @param whichValue - Which value from Matrix.M* to return
 * @return float - returned value
 */
private float getValue(Matrix matrix, int whichValue) {
    matrix.getValues(mMatrixValues);
    return mMatrixValues[whichValue];
}
 
Example 19
Source File: PhotoViewAttacher.java    From MNImageBrowser with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Helper method that 'unpacks' a Matrix and returns the required value
 *
 * @param matrix     Matrix to unpack
 * @param whichValue Which value from Matrix.M* to return
 * @return returned value
 */
private float getValue(Matrix matrix, int whichValue) {
    matrix.getValues(mMatrixValues);
    return mMatrixValues[whichValue];
}
 
Example 20
Source File: PhotoViewAttacher.java    From PicturePicker with Apache License 2.0 2 votes vote down vote up
/**
 * Helper method that 'unpacks' a Matrix and returns the required value
 *
 * @param matrix     - Matrix to unpack
 * @param whichValue - Which value from Matrix.M* to return
 * @return float - returned value
 */
private float getValue(Matrix matrix, int whichValue) {
    matrix.getValues(mMatrixValues);
    return mMatrixValues[whichValue];
}