Java Code Examples for android.graphics.Matrix.MSCALE_Y

The following are Jave code examples for showing how to use MSCALE_Y 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: AndroidShareElement   File: ShareElementInfo.java   Source Code and License Vote up 7 votes
void convertTargetInfo(ImageView tarView, Context context) {
    if (tarView == null || tarView.getDrawable() == null) {
        throw new NullPointerException("target ImageView or ImageView drawable must not null");
    }

    //get target ImageView info
    tarView.getImageMatrix().getValues(mTargetValues);
    Rect tarRect = tarView.getDrawable().getBounds();
    mTargetWidth = (int) (tarRect.width() * mTargetValues[Matrix.MSCALE_X]);
    mTargetHeight = (int) (tarRect.height() * mTargetValues[Matrix.MSCALE_Y]);

    mTargetViewWidth = tarView.getWidth();
    mTargetViewHeight = tarView.getHeight();
    tarView.getLocationOnScreen(mTargetLocation);

    init(context);
}
 
Example 2
Project: GitHub   File: ViewPortHandler.java   Source Code and License Vote up 6 votes
/**
 * Resets all zooming and dragging and makes the chart fit exactly it's
 * bounds.  Output Matrix is available for those who wish to cache the object.
 */
public void fitScreen(Matrix outputMatrix) {
    mMinScaleX = 1f;
    mMinScaleY = 1f;

    outputMatrix.set(mMatrixTouch);

    float[] vals = valsBufferForFitScreen;
    for (int i = 0; i < 9; i++) {
        vals[i] = 0;
    }

    outputMatrix.getValues(vals);

    // reset all translations and scaling
    vals[Matrix.MTRANS_X] = 0f;
    vals[Matrix.MTRANS_Y] = 0f;
    vals[Matrix.MSCALE_X] = 1f;
    vals[Matrix.MSCALE_Y] = 1f;

    outputMatrix.setValues(vals);
}
 
Example 3
Project: Hotspot-master-devp   File: MatrixImageView.java   Source Code and License Vote up 6 votes
/**
 *   重置Matrix
 */
private void reSetMatrix() {
    if(checkRest()){
        mCurrentMatrix.set(mMatrix);
        setImageMatrix(mCurrentMatrix);
    }else {
        //判断Y轴是否需要更正
        float[] values=new float[9];
        getImageMatrix().getValues(values);
        float height=mImageHeight*values[Matrix.MSCALE_Y];
        if(height<getHeight()){
            //在图片真实高度小于容器高度时,Y轴居中,Y轴理想偏移量为两者高度差/2,
            float topMargin=(getHeight()-height)/2;
            if(topMargin!=values[Matrix.MTRANS_Y]){
                mCurrentMatrix.set(getImageMatrix());
                mCurrentMatrix.postTranslate(0, topMargin-values[Matrix.MTRANS_Y]);
                setImageMatrix(mCurrentMatrix);
            }
        }

    }
}
 
Example 4
Project: MontageCam   File: AddTextFragment.java   Source Code and License Vote up 6 votes
@Override
public void handleImage(Canvas canvas, Matrix m) {
    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);
    //System.out.println("scale = " + scale_x + "       " + scale_y + "     " + dx + "
    // " + dy);
    mTextStickerView.drawText(canvas, mTextStickerView.layout_x, mTextStickerView
            .layout_y, mTextStickerView.mScale, mTextStickerView.mRotateAngle);
    canvas.restore();
}
 
Example 5
Project: MontageCam   File: HollowFragment.java   Source Code and License Vote up 6 votes
@Override
public void handleImage(Canvas canvas, Matrix m) {
    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.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    canvas.save();
    canvas.translate(dx, dy);
    canvas.scale(scale_x, scale_y);

    if (mHollowView.getPaintBit() != null) {
        canvas.drawBitmap(mHollowView.getPaintBit(), 0, 0, null);
    }
    canvas.restore();
}
 
Example 6
Project: MontageCam   File: PaintFragment.java   Source Code and License Vote up 6 votes
@Override
public void handleImage(Canvas canvas, Matrix m) {
    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);

    if (mPaintView.getPaintBit() != null) {
        canvas.drawBitmap(mPaintView.getPaintBit(), 0, 0, null);
    }
    canvas.restore();
}
 
Example 7
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 8
Project: AndroidShareElement   File: ShareElementInfo.java   Source Code and License Vote up 6 votes
public void convertOriginalInfo(ImageView oriView) {
    if (oriView == null || oriView.getDrawable() == null) {
        throw new NullPointerException("original ImageView or ImageView drawable must not null");
    }

    //get original ImageView info
    oriView.getImageMatrix().getValues(mOriginalValues);
    Rect oriRect = oriView.getDrawable().getBounds();
    mOriginalWidth = (int) (oriRect.width() * mOriginalValues[Matrix.MSCALE_X]);
    mOriginalHeight = (int) (oriRect.height() * mOriginalValues[Matrix.MSCALE_Y]);

    mOriginalViewWidth = oriView.getWidth();
    mOriginalViewHeight = oriView.getHeight();
    oriView.getLocationOnScreen(mOriginalLocation);
}
 
Example 9
Project: PinchToZoom   File: ImageMatrixTouchHandler.java   Source Code and License Vote up 6 votes
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
	if (mode == DRAG) {
		if (flingDuration > 0 && !isAnimating()) {
			float factor = ((float) flingDuration / 1000f) * flingExaggeration;
			float[] values = corrector.getValues();
			float dx = (velocityX * factor) * values[Matrix.MSCALE_X];
			float dy = (velocityY * factor) * values[Matrix.MSCALE_Y];
			PropertyValuesHolder flingX = PropertyValuesHolder.ofFloat(FlingAnimatorHandler.PROPERTY_TRANSLATE_X, values[Matrix.MTRANS_X], values[Matrix.MTRANS_X] + dx);
			PropertyValuesHolder flingY = PropertyValuesHolder.ofFloat(FlingAnimatorHandler.PROPERTY_TRANSLATE_Y, values[Matrix.MTRANS_Y], values[Matrix.MTRANS_Y] + dy);
			valueAnimator = ValueAnimator.ofPropertyValuesHolder(flingX, flingY);
			valueAnimator.setDuration(flingDuration);
			valueAnimator.addUpdateListener(new FlingAnimatorHandler(corrector));
			valueAnimator.setInterpolator(new DecelerateInterpolator());
			valueAnimator.start();
			return true;
		}
	}
	return super.onFling(e1, e2, velocityX, velocityY);
}
 
Example 10
Project: PinchToZoom   File: ImageViewerCorrector.java   Source Code and License Vote up 6 votes
@Override
public float correctAbsolute(int vector, float x) {
	switch(vector) {
		case Matrix.MTRANS_X:
			return correctTranslation(x, getImageView().getWidth(), getScaledImageWidth());
		case Matrix.MTRANS_Y:
			return correctTranslation(x, getImageView().getHeight(), getScaledImageHeight());
		case Matrix.MSCALE_X:
		case Matrix.MSCALE_Y:
			float innerFitScale = getInnerFitScale();
			float maxScale = maxScaleRelative ? innerFitScale * this.maxScale : this.maxScale;
			return Math.max(Math.min(x, maxScale), innerFitScale);
		default:
			throw new IllegalArgumentException("Vector not supported");
	}
}
 
Example 11
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 12
Project: RLibrary   File: RUtils.java   Source Code and License Vote up 5 votes
/**
 * 一个矩形(from), 在另一个矩形(to),居中显示时的宽高度
 */
public static int[] getCenterRectWidthHeight(RectF from, RectF to) {
    int[] result = new int[2];

    Matrix matrix = new Matrix();
    matrix.setRectToRect(from, to, Matrix.ScaleToFit.CENTER);
    float[] matrixValues = new float[9];
    matrix.getValues(matrixValues);

    result[0] = (int) (matrixValues[Matrix.MSCALE_X] * from.width());//缩放之后的宽度
    result[1] = (int) (matrixValues[Matrix.MSCALE_Y] * from.height());//缩放之后的高度

    return result;
}
 
Example 13
Project: Hotspot-master-devp   File: MatrixImageView.java   Source Code and License Vote up 5 votes
/**
 *  和当前矩阵对比,检验dy,使图像移动后不会超出ImageView边界
 *  @param values
 *  @param dy
 *  @return
 */
private float checkDyBound(float[] values, float dy) {
    float height=getHeight();
    if(mImageHeight*values[Matrix.MSCALE_Y]<height)
        return 0;
    if(values[Matrix.MTRANS_Y]+dy>0)
        dy=-values[Matrix.MTRANS_Y];
    else if(values[Matrix.MTRANS_Y]+dy<-(mImageHeight*values[Matrix.MSCALE_Y]-height))
        dy=-(mImageHeight*values[Matrix.MSCALE_Y]-height)-values[Matrix.MTRANS_Y];
    return dy;
}
 
Example 14
Project: FragmentRigger   File: ImageViewUtil.java   Source Code and License Vote up 5 votes
/**
 * Returns the bitmap position inside an imageView.
 *
 * @param imageView source ImageView
 *
 * @return 0: left, 1: top, 2: width, 3: height
 */
public static int[] getDisplayedImageLocation(ImageView imageView) {
  int[] ret = new int[4];

  if (imageView == null || imageView.getDrawable() == null)
    return ret;

  // Get image dimensions
  // Get image matrix values and place them in an array
  float[] f = new float[9];
  imageView.getImageMatrix().getValues(f);

  // Extract the scale values using the constants (if aspect ratio maintained, scaleX == scaleY)
  final float scaleX = f[Matrix.MSCALE_X];
  final float scaleY = f[Matrix.MSCALE_Y];

  // Get the drawable (could also get the bitmap behind the drawable and getWidth/getHeight)
  final Drawable d = imageView.getDrawable();
  final int origW = d.getIntrinsicWidth();
  final int origH = d.getIntrinsicHeight();

  // Calculate the actual dimensions
  final int actW = Math.round(origW * scaleX);
  final int actH = Math.round(origH * scaleY);

  ret[2] = actW;
  ret[3] = actH;

  // Get image position
  // We assume that the image is centered into ImageView
  int imgViewW = imageView.getWidth();
  int imgViewH = imageView.getHeight();

  int[] imgViewScreenLoc = new int[2];
  imageView.getLocationOnScreen(imgViewScreenLoc);

  // get the actual image location inside its image view
  int left = imgViewScreenLoc[0] + (imgViewW - actW) / 2;
  int top = imgViewScreenLoc[1] + (imgViewH - actH) / 2;

  ret[0] = left;
  ret[1] = top;

  return ret;
}
 
Example 15
Project: PlusGram   File: GLMatrix.java   Source Code and License Vote up 5 votes
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 16
Project: PinchToZoom   File: MatrixCorrector.java   Source Code and License Vote up 5 votes
/**
 * <p>Returns the corrected value of the given relative vector.</p>
 * @param vector
 * @param x
    * @return
    */
public float correctRelative(int vector, float x) {
	float v = getValues()[vector];
	switch(vector) {
		case Matrix.MTRANS_X:
		case Matrix.MTRANS_Y:
			return correctAbsolute(vector, v + x) - v;
		case Matrix.MSCALE_X:
		case Matrix.MSCALE_Y:
			return correctAbsolute(vector, v * x) / v;
		default:
			throw new IllegalArgumentException("Vector not supported");
	}
}
 
Example 17
Project: RLibrary   File: DragPhotoView.java   Source Code and License Vote up 5 votes
/**
     * 放大之后的图片高度
     */
    public int getCurrentImageHeight() {
        Drawable drawable = getDrawable();
        int viewWidth = getMeasuredWidth();
        int viewHeight = getMeasuredHeight();

        if (drawable != null) {
            float scale = getScale();
            int width = drawable.getIntrinsicWidth();
            int height = drawable.getIntrinsicHeight();

            int widthPixels = getResources().getDisplayMetrics().widthPixels;

            Matrix mBaseMatrix = new Matrix();
            RectF mTempSrc = new RectF(0, 0, width, height);
            RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);
            mBaseMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.CENTER);
            float[] mMatrixValues = new float[9];
            mBaseMatrix.getValues(mMatrixValues);

            int scaleWidth = (int) (mMatrixValues[Matrix.MSCALE_X] * width);//缩放之后的宽度
            int scaleHeight = (int) (mMatrixValues[Matrix.MSCALE_Y] * height);//缩放之后的高度

            return (int) Math.min(viewHeight, scaleHeight * scale);

//            if (width > height) {
//                //宽图
//                return (int) (scale * (widthPixels * 1f / width * height));
//            } else {
//                //长图
//                return Math.min(getMeasuredHeight(), height);
//            }
        }
        return getMeasuredHeight();
    }
 
Example 18
Project: PinchToZoom   File: ImageMatrixCorrector.java   Source Code and License Vote up 5 votes
/**
 * <p>(Re)calculates the image's current dimensions.</p>
 */
protected void updateScaledImageDimensions() {
	float[] values = getValues();
	Drawable drawable = imageView.getDrawable();
	if(drawable != null) {
		scaledImageWidth = values[Matrix.MSCALE_X] * drawable.getIntrinsicWidth();
		scaledImageHeight = values[Matrix.MSCALE_Y] * drawable.getIntrinsicHeight();
	} else {
		scaledImageWidth = scaledImageHeight = 0f;
	}
}
 
Example 19
Project: Hotspot-master-devp   File: MatrixImageView.java   Source Code and License Vote up 4 votes
/**
 *  设置缩放Matrix
 *  @param event
 */
private void setZoomMatrix(MotionEvent event) {
    //只有同时触屏两个点的时候才执行
    if(event.getPointerCount()<2) return;
    float endDis = distance(event);// 结束距离
    if (endDis > 10f) { // 两个手指并拢在一起的时候像素大于10
        float scale = endDis / mStartDis;// 得到缩放倍数

        mCurrentMatrix.set(getImageMatrix());//初始化Matrix
        float[] values=new float[9];
        mCurrentMatrix.getValues(values);
        scale = checkMaxScale(scale, values);
        Log.d("缩放倍数", scale+"");
        //PointF centerF=getCenter(scale,values);
        //mCurrentMatrix.postScale(scale, scale,centerF.x,centerF.y);
        //setImageMatrix(mCurrentMatrix);
        //checkRest();
        float scaledWidth = mImageWidth * values[Matrix.MSCALE_X]*scale;
        float scaledHeight = mImageHeight * values[Matrix.MSCALE_Y]*scale;
        totalTranslateX = values[Matrix.MTRANS_X];
        totalTranslateY = values[Matrix.MTRANS_Y];
        //test
        float translateX = 0f;
        float translateY = 0f;
        float xPoint0 = event.getX(0);
        float yPoint0 = event.getY(0);
        float xPoint1 = event.getX(1);
        float yPoint1 = event.getY(1);
        float centerPointX = (xPoint0 + xPoint1) / 2;
        float centerPointY = (yPoint0 + yPoint1) / 2;
        if (currentBitmapWidth < getWidth()){
            translateX = (getWidth() - scaledWidth)/ 2f;
        } else {
            translateX = totalTranslateX*scale + centerPointX * (1 - scale);
            // 进行边界检查,保证图片缩放后在水平方向上不会偏移出屏幕
            if (translateX > 0) {
                translateX = 0;
            } else if (getWidth() - translateX > scaledWidth) {
                translateX = getWidth() - scaledWidth;
            }
        }
        // 如果当前图片高度小于屏幕高度,则按屏幕中心的纵坐标进行垂直缩放。否则按两指的中心点的纵坐标进行垂直缩放
        if (currentBitmapHeight < getHeight()) {
            translateY = (getHeight() - scaledHeight) / 2f;
        } else {
            translateY = totalTranslateY * scale + centerPointY * (1 - scale);
            // 进行边界检查,保证图片缩放后在垂直方向上不会偏移出屏幕
            if (translateY > 0) {
                translateY = 0;
            } else if (getHeight() - translateY > scaledHeight) {
                translateY = getHeight() - scaledHeight;
            }
        }

        // 缩放后对图片进行偏移,以保证缩放后中心点位置不变

        Matrix matrix = new Matrix();
        matrix.reset();
        matrix.postScale(values[Matrix.MSCALE_X]*scale, values[Matrix.MSCALE_Y]*scale);
        matrix.postTranslate(translateX, translateY);
        //mCurrentMatrix.preTranslate(translateX, translateY);
        //mCurrentMatrix.postScale(scale,scale);
        //totalTranslateX = translateX;
        //totalTranslateY = translateY;
        currentBitmapWidth = scaledWidth;
        currentBitmapHeight = scaledHeight;
        setImageMatrix(matrix);
        checkRest();
        mStartDis=endDis;//重置距离
    }
}
 
Example 20
Project: BubbleView   File: BubbleImageView.java   Source Code and License Vote up 4 votes
@Override
protected void onDraw(Canvas canvas) {
    if (bubbleDrawable == null) {
        return; // couldn't resolve the URI
    }

    if (bubbleDrawable.getIntrinsicHeight() == 0 || bubbleDrawable.getIntrinsicWidth() == 0) {
        return;     // nothing to draw (empty bounds)
    }

    final Matrix mDrawMatrix = getImageMatrix();
    final int mPaddingLeft = getPaddingLeft();
    final int mPaddingTop = getPaddingTop();

    if (mDrawMatrix == null && getPaddingTop() == 0 && getPaddingLeft() == 0) {
        bubbleDrawable.draw(canvas);
    } else {
        final int saveCount = canvas.getSaveCount();
        canvas.save();

        //crop to padding api above 16
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            if (getCropToPadding()) {
                final int scrollX = getScrollX();
                final int scrollY = getScrollY();
                canvas.clipRect(scrollX + mPaddingLeft, scrollY + mPaddingTop,
                        scrollX + getRight() - getLeft() - getRight(),
                        scrollY + getBottom() - getTop() - getBottom());
            }
        }

        canvas.translate(mPaddingLeft, mPaddingTop);

        if (mDrawMatrix != null) {
            canvas.concat(mDrawMatrix);

            mDrawMatrix.getValues(matrixValues);
            final float scaleX = matrixValues[Matrix.MSCALE_X];
            final float scaleY = matrixValues[Matrix.MSCALE_Y];
            final float translateX = matrixValues[Matrix.MTRANS_X];
            final float translateY = matrixValues[Matrix.MTRANS_Y];

            final ScaleType scaleType = getScaleType();

            if (scaleType == ScaleType.CENTER) {
                bubbleDrawable.setOffsetLeft(-translateX);
                bubbleDrawable.setOffsetTop(-translateY);
                bubbleDrawable.setOffsetBottom(-translateY);
                bubbleDrawable.setOffsetRight(-translateX);
            } else if (scaleType == ScaleType.CENTER_CROP) {
                float scale = scaleX > scaleY ? 1 / scaleY : 1 / scaleX;
                bubbleDrawable.setOffsetLeft(-translateX * scale);
                bubbleDrawable.setOffsetTop(-translateY * scale);
                bubbleDrawable.setOffsetBottom(-translateY * scale);
                bubbleDrawable.setOffsetRight(-translateX * scale);
                bubbleDrawable.setScale(scale);
            } else {
                bubbleDrawable.setScale(scaleX > scaleY ? 1 / scaleY : 1 / scaleX);
            }
        }

        bubbleDrawable.draw(canvas);
        canvas.restoreToCount(saveCount);
    }
}