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

The following are Jave code examples for showing how to use getValues() of the android.graphics.Matrix class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: PinchToZoom   File: ImageViewPager.java   Source Code and License Vote up 7 votes
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if(v instanceof ImageView) {
        ImageView iv = (ImageView) v;
        Drawable drawable = iv.getDrawable();
        if(drawable != null) {
            float vw = iv.getWidth();
            float vh = iv.getHeight();
            float dw = drawable.getIntrinsicWidth();
            float dh = drawable.getIntrinsicHeight();

            Matrix matrix = iv.getImageMatrix();
            matrix.getValues(VALUES);
            float tx = VALUES[Matrix.MTRANS_X] + dx;
            float sdw = dw * VALUES[Matrix.MSCALE_X];

            //Log.d(TAG, "sdw: " + sdw + " vw: " + vw);

            return VALUES[Matrix.MSCALE_X] / centerInsideScale(vw, vh, dw, dh) > scaleThreshold && !translationExceedsBoundary(tx, vw, sdw) && sdw > vw && pointerCount == 1; // Assumes x-y scales are equal
        }
    }
    return super.canScroll(v, checkV, dx, x, y);
}
 
Example 2
Project: GitHub   File: ScalingUtils.java   Source Code and License Vote up 6 votes
@Override
public Matrix getTransform(
    Matrix transform,
    Rect parentBounds,
    int childWidth,
    int childHeight,
    float focusX,
    float focusY) {
  Rect boundsFrom = (mBoundsFrom != null) ? mBoundsFrom : parentBounds;
  Rect boundsTo = (mBoundsTo != null) ? mBoundsTo : parentBounds;

  mScaleTypeFrom.getTransform(transform, boundsFrom, childWidth, childHeight, focusX, focusY);
  transform.getValues(mMatrixValuesFrom);
  mScaleTypeTo.getTransform(transform, boundsTo, childWidth, childHeight, focusX, focusY);
  transform.getValues(mMatrixValuesTo);

  for (int i = 0; i < 9; i++) {
    mMatrixValuesInterpolated[i] = mMatrixValuesFrom[i] * (1 - mInterpolatingValue) +
        mMatrixValuesTo[i] * mInterpolatingValue;
  }
  transform.setValues(mMatrixValuesInterpolated);
  return transform;
}
 
Example 3
Project: MontageCam   File: BitmapUtils.java   Source Code and License Vote up 6 votes
public static Bitmap restoreBitmap(Bitmap src, Matrix matrix, int w, int h) {
    Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());
    result.setDensity(src.getDensity());
    Canvas canvas = new Canvas(result);
    float[] data = new float[9];
    matrix.getValues(data);// 底部图片变化记录矩阵原始数据
    Matrix3 cal = new Matrix3(data);// 辅助矩阵计算类
    Matrix3 inverseMatrix = cal.inverseMatrix();// 计算逆矩阵
    Matrix m = new Matrix();
    m.setValues(inverseMatrix.getValues());
    float[] f = new float[9];
    m.getValues(f);
    int dx = (int) f[Matrix.MTRANS_X];
    int dy = (int) f[Matrix.MTRANS_Y];
    float scale_x = f[Matrix.MSCALE_X];
    float scale_y = f[Matrix.MSCALE_Y];
    canvas.save();
    canvas.translate(dx, dy);
    canvas.scale(scale_x, scale_y);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.restore();
    return result;
}
 
Example 4
Project: MontageCam   File: CropFragment.java   Source Code and License Vote up 6 votes
@SuppressWarnings("WrongThread")
   @Override
   protected Bitmap doInBackground(Bitmap... params) {
       RectF cropRect = mCropPanel.getCropRect();// 剪切区域矩形
       Matrix touchMatrix = activity.mainImage.getImageViewMatrix();
       // Canvas canvas = new Canvas(resultBit);
       float[] data = new float[9];
       touchMatrix.getValues(data);// 底部图片变化记录矩阵原始数据
       Matrix3 cal = new Matrix3(data);// 辅助矩阵计算类
       Matrix3 inverseMatrix = cal.inverseMatrix();// 计算逆矩阵
       Matrix m = new Matrix();
       m.setValues(inverseMatrix.getValues());
       m.mapRect(cropRect);// 变化剪切矩形

       // Paint paint = new Paint();
       // paint.setColor(Color.RED);
       // paint.setStrokeWidth(10);
       // canvas.drawRect(cropRect, paint);
       // Bitmap resultBit = Bitmap.createBitmap(params[0]).copy(
       // Bitmap.Config.ARGB_8888, true);
       Bitmap resultBit = Bitmap.createBitmap(params[0], (int) cropRect.left, (int) cropRect
.top, (int) cropRect.width(), (int) cropRect.height());

       //saveBitmap(resultBit, activity.saveFilePath);
       return resultBit;
   }
 
Example 5
Project: greendao_expand   File: CircleProgressView.java   Source Code and License Vote up 6 votes
private static float calcTextSizeForRect(String _text, Paint _textPaint, RectF _rectBounds) {

        Matrix matrix = new Matrix();
        Rect textBoundsTmp = new Rect();
        //replace ones because for some fonts the 1 takes less space which causes issues
        String text = _text.replace('1', '0');

        //get current mText bounds
        _textPaint.getTextBounds(text, 0, text.length(), textBoundsTmp);

        RectF textBoundsTmpF = new RectF(textBoundsTmp);

        matrix.setRectToRect(textBoundsTmpF, _rectBounds, Matrix.ScaleToFit.CENTER);
        float values[] = new float[9];
        matrix.getValues(values);
        return _textPaint.getTextSize() * values[Matrix.MSCALE_X];
    }
 
Example 6
Project: MovingGdufe-Android   File: PinchImageView.java   Source Code and License Vote up 5 votes
/**
 * 获取矩阵的缩放值
 *
 * @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 7
Project: GitHub   File: ViewPortHandler.java   Source Code and License Vote up 5 votes
/**
 * 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 8
Project: sealtalk-android-master   File: SelectableRoundedImageView.java   Source Code and License Vote up 5 votes
private void applyScaleToRadii(Matrix m) {
    float[] values = new float[9];
    m.getValues(values);
    for (int i = 0; i < mRadii.length; i++) {
        mRadii[i] = mRadii[i] / values[0];
    }
}
 
Example 9
Project: FinalProject   File: RoundedImageView.java   Source Code and License Vote up 5 votes
private void applyScaleToRadii(Matrix m) {
    float[] values = new float[9];
    m.getValues(values);
    for (int i = 0; i < mRadii.length; i++) {
        mRadii[i] = mRadii[i] / values[0];
    }
}
 
Example 10
Project: Android-Code-Demos   File: Rotate3DAnimation.java   Source Code and License Vote up 5 votes
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromDegrees = mFromDegrees;
    float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Camera camera = mCamera;
    final Matrix matrix = t.getMatrix();
    camera.save();

    // 调节深度
    if (mReverse)
        camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
    else
        camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));

    // 绕y轴旋转
    camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();

    // 修正失真,主要修改 MPERSP_0 和 MPERSP_1
    float[] mValues = new float[9];
    matrix.getValues(mValues);              //获取数值
    mValues[6] = mValues[6] / scale;        //数值修正
    mValues[7] = mValues[7] / scale;        //数值修正
    matrix.setValues(mValues);              //重新赋值

    // 调节中心点
    matrix.preTranslate(-centerX, -centerY);
    matrix.postScale(centerX, centerY);

}
 
Example 11
Project: exciting-app   File: MatrixUtils.java   Source Code and License Vote up 4 votes
public static float[] getScale(Matrix matrix) {
    float[] points = new float[9];
    matrix.getValues(points);
    return new float[]{points[0], points[4]};
}
 
Example 12
Project: MontageCam   File: ImageViewTouchBase.java   Source Code and License Vote up 4 votes
protected float getValue(Matrix matrix, int whichValue) {
    matrix.getValues(mMatrixValues);
    return mMatrixValues[whichValue];
}
 
Example 13
Project: android-titanium-imagecropper   File: CropImageAnimation.java   Source Code and License Vote up 4 votes
public void setEndState(float[] boundPoints, Matrix imageMatrix) {
  System.arraycopy(boundPoints, 0, mEndBoundPoints, 0, 8);
  mEndCropWindowRect.set(mCropOverlayView.getCropWindowRect());
  imageMatrix.getValues(mEndImageMatrix);
}
 
Example 14
Project: Android-Demo_ImageCroper   File: CropImageAnimation.java   Source Code and License Vote up 4 votes
public void setEndState(float[] boundPoints, Matrix imageMatrix) {
    System.arraycopy(boundPoints, 0, mEndBoundPoints, 0, 8);
    mEndCropWindowRect.set(mCropOverlayView.getCropWindowRect());
    imageMatrix.getValues(mEndImageMatrix);
}
 
Example 15
Project: CommentGallery   File: DefaultZoomableController.java   Source Code and License Vote up 4 votes
private float getMatrixTranslateY(Matrix transform) {
    transform.getValues(mTempValues);
    return mTempValues[Matrix.MTRANS_Y];
}
 
Example 16
Project: Zoomable   File: DefaultZoomableController.java   Source Code and License Vote up 4 votes
/**
 * Gets the scale factor for the given matrix.
 * This method assumes the equal scaling factor for X and Y axis.
 */
private float getMatrixScaleFactor(Matrix transform) {
  transform.getValues(mTempValues);
  return mTempValues[Matrix.MSCALE_X];
}
 
Example 17
Project: EasyTodo   File: PinchImageView.java   Source Code and License Vote up 3 votes
/**
 * 构建一个缩放动画
 *
 * 从一个矩阵变换到另外一个矩阵
 *
 * @param start 开始矩阵
 * @param end 结束矩阵
 * @param duration 动画时间
 */
public ScaleAnimator(Matrix start, Matrix end, long duration) {
    super();
    setFloatValues(0, 1f);
    setDuration(duration);
    addUpdateListener(this);
    start.getValues(mStart);
    end.getValues(mEnd);
}
 
Example 18
Project: PhotoPickApp   File: PhotoViewAttacher.java   Source Code and License Vote up 2 votes
/**
 * 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 19
Project: CXJPadProject   File: PhotoViewAttacher.java   Source Code and License Vote up 2 votes
/**
 * 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 20
Project: Recognize-it   File: PhotoViewAttacher.java   Source Code and License Vote up 2 votes
/**
 * 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];
}