MSCALE_Y源码实例Demo

android.graphics.Matrix#MSCALE_Y源码实例Demo

下面列出了android.graphics.Matrix#MSCALE_Y 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: star-zone-android   文件: GalleryPhotoView.java
private Rect getDrawableBounds(Drawable d) {
    if (d == null) return null;
    Rect result = new Rect();
    Rect tDrawableRect = d.getBounds();
    Matrix drawableMatrix = getImageMatrix();

    float[] values = new float[9];
    drawableMatrix.getValues(values);

    result.left = (int) values[Matrix.MTRANS_X];
    result.top = (int) values[Matrix.MTRANS_Y];
    result.right = (int) (result.left + tDrawableRect.width() * values[Matrix.MSCALE_X]);
    result.bottom = (int) (result.top + tDrawableRect.height() * values[Matrix.MSCALE_Y]);

    return result;
}
 
源代码2 项目: iMoney   文件: ViewPortHandler.java
/**
 * Resets all zooming and dragging and makes the chart fit exactly it's
 * bounds.
 */
public Matrix fitScreen() {
    
    mMinScaleX = 1f;
    mMinScaleY = 1f;

    Matrix save = new Matrix();
    save.set(mMatrixTouch);

    float[] vals = new float[9];

    save.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;

    save.setValues(vals);

    return save;
}
 
源代码3 项目: PinchToZoom   文件: ImageViewUtils.java
/**
 *
 * @param imageView
 * @param width
 * @param height
 */
public static final void updateImageViewMatrix(ImageView imageView, float width, float height) {
    Drawable drawable = imageView.getDrawable();
    if(drawable == null) {
        throw new NullPointerException("ImageView drawable is null");
    }
    Matrix matrix = imageView.getImageMatrix();
    if(!matrix.isIdentity()) {
        float[] values = new float[9];
        matrix.getValues(values);

        RectF src = new RectF();
        src.left = 0;
        src.top = 0;
        src.right = width;
        src.bottom = height;

        RectF dst = new RectF();
        dst.left = values[Matrix.MTRANS_X];
        dst.top = values[Matrix.MTRANS_Y];
        dst.right = dst.left + (drawable.getIntrinsicWidth() * values[Matrix.MSCALE_X]);
        dst.bottom = dst.top + (drawable.getIntrinsicHeight() * values[Matrix.MSCALE_Y]);

        matrix.setRectToRect(src, dst, Matrix.ScaleToFit.CENTER);
    }
}
 
源代码4 项目: Stayfit   文件: ViewPortHandler.java
/**
 * Resets all zooming and dragging and makes the chart fit exactly it's
 * bounds.
 */
public Matrix fitScreen() {

    mMinScaleX = 1f;
    mMinScaleY = 1f;

    Matrix save = new Matrix();
    save.set(mMatrixTouch);

    float[] vals = new float[9];

    save.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;

    save.setValues(vals);

    return save;
}
 
源代码5 项目: LLApp   文件: MatrixImageView.java
/**  
 *   重置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);
			}
		}
	}
}
 
源代码6 项目: JNChartDemo   文件: ViewPortHandler.java
/**
 * Resets all zooming and dragging and makes the chart fit exactly it's
 * bounds.
 */
public Matrix fitScreen() {

    mMinScaleX = 1f;
    mMinScaleY = 1f;

    Matrix save = new Matrix();
    save.set(mMatrixTouch);

    float[] vals = new float[9];

    save.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;

    save.setValues(vals);

    return save;
}
 
源代码7 项目: Ticket-Analysis   文件: ViewPortHandler.java
/**
 * 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);
}
 
源代码8 项目: android-kline   文件: ViewPortHandler.java
/**
 * 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);
}
 
源代码9 项目: scene   文件: ChangeTransform.java
public static float scaleValue(Matrix matrix) {
    float[] f = new float[9];
    matrix.getValues(f);

    float scaleX = f[Matrix.MSCALE_X];
    float scaleY = f[Matrix.MSCALE_Y];
    return scaleX;
}
 
源代码10 项目: TelePlus-Android   文件: GLMatrix.java
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;
}
 
源代码11 项目: LLApp   文件: MatrixImageView.java
/**  
 *   初始化模板Matrix和图片的其他数据
 */
private void initData() {
	//设置完图片后,获取该图片的坐标变换矩阵
	mMatrix.set(getImageMatrix());
	float[] values=new float[9];
	mMatrix.getValues(values);
	//图片宽度为屏幕宽度除缩放倍数
	mImageWidth=getWidth()/values[Matrix.MSCALE_X];
	mImageHeight=(getHeight()-values[Matrix.MTRANS_Y]*2)/values[Matrix.MSCALE_Y];
	mScale=values[Matrix.MSCALE_X];
}
 
源代码12 项目: ByakuGallery   文件: TouchImageView.java
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
	loadMatrixValues();

	if(interpolatedTime >= 1) {
		mMatrix.getValues(mMatrixValues);
		mMatrixValues[Matrix.MSCALE_X] = this.targetScale;
		mMatrixValues[Matrix.MSCALE_Y] = this.targetScale;
		mMatrixValues[Matrix.MTRANS_X] = this.targetTranslationX;
		mMatrixValues[Matrix.MTRANS_Y] = this.targetTranslationY;
		mMatrix.setValues(mMatrixValues);

	} else {
		final float scaleFactor = (this.initialScale + interpolatedTime * (this.targetScale - this.initialScale)) / mScale;
		mMatrix.postScale(scaleFactor, scaleFactor);

		mMatrix.getValues(mMatrixValues);
		final float currentTranslationX = mMatrixValues[Matrix.MTRANS_X];
		final float currentTranslationY = mMatrixValues[Matrix.MTRANS_Y];

		final float dx = this.initialTranslationX + interpolatedTime * (this.targetTranslationX - this.initialTranslationX) - currentTranslationX;
		final float dy = this.initialTranslationY + interpolatedTime * (this.targetTranslationY - this.initialTranslationY) - currentTranslationY;
		mMatrix.postTranslate(dx, dy);
	}

	ViewCompat.postInvalidateOnAnimation(TouchImageView.this);
}
 
public void syncCharts() {
    if (dstCharts == null) {
        return;
    }
    Matrix srcMatrix;
    float[] srcVals = new float[9];
    Matrix dstMatrix;
    float[] dstVals = new float[9];
    // get src chart translation matrix:
    srcMatrix = srcChart.getViewPortHandler().getMatrixTouch();
    srcMatrix.getValues(srcVals);

    // apply X axis scaling and position to dst charts:
    for (Chart dstChart : dstCharts) {
        if (dstChart.getVisibility() == View.VISIBLE) {
            dstMatrix = dstChart.getViewPortHandler().getMatrixTouch();
            dstMatrix.getValues(dstVals);

            dstVals[Matrix.MSCALE_X] = srcVals[Matrix.MSCALE_X];
            dstVals[Matrix.MSKEW_X] = srcVals[Matrix.MSKEW_X];
            dstVals[Matrix.MTRANS_X] = srcVals[Matrix.MTRANS_X];
            dstVals[Matrix.MSKEW_Y] = srcVals[Matrix.MSKEW_Y];
            dstVals[Matrix.MSCALE_Y] = srcVals[Matrix.MSCALE_Y];
            dstVals[Matrix.MTRANS_Y] = srcVals[Matrix.MTRANS_Y];
            dstVals[Matrix.MPERSP_0] = srcVals[Matrix.MPERSP_0];
            dstVals[Matrix.MPERSP_1] = srcVals[Matrix.MPERSP_1];
            dstVals[Matrix.MPERSP_2] = srcVals[Matrix.MPERSP_2];

            dstMatrix.setValues(dstVals);
            dstChart.getViewPortHandler().refresh(dstMatrix, dstChart, true);
        }
    }
}
 
源代码14 项目: Loop   文件: LoadingImageView.java
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    getImageMatrix().getValues(f);
    scaleX = f[Matrix.MSCALE_X];
    scaleY = f[Matrix.MSCALE_Y];
}
 
源代码15 项目: JNChartDemo   文件: ViewPortHandler.java
/**
 * 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);
}
 
源代码16 项目: ShareBox   文件: DragImageView.java
@Override
public void setImageBitmap(Bitmap bm) {
    // TODO Auto-generated method stub
    super.setImageBitmap(bm);
    //设置完图片后,获取该图片的坐标变换矩阵
    mMatrix.set(getImageMatrix());
    float[] values = new float[9];
    mMatrix.getValues(values);
    //图片宽度为屏幕宽度除缩放倍数
    mImageWidth = getWidth() / values[Matrix.MSCALE_X];
    mImageHeight = (getHeight() - values[Matrix.MTRANS_Y] * 2) / values[Matrix.MSCALE_Y];
}
 
源代码17 项目: BubbleView   文件: BubbleImageView.java
@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);
    }
}
 
源代码18 项目: zulip-android   文件: PhotoHelper.java
/**
 * From http://stackoverflow.com/a/26930938/5334314
 * Returns the actual bitmap position in an imageView.
 *
 * @param imageView source ImageView
 * @return 0: left, 1: top, 2: width, 3: height
 */
public static int[] getBitmapPositionInsideImageView(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 top = (int) (imgViewH - actH) / 2;
    int left = (int) (imgViewW - actW) / 2;

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

    return ret;
}
 
源代码19 项目: ploggy   文件: TouchImageView.java
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    Drawable drawable = getDrawable();
    if (drawable == null || drawable.getIntrinsicWidth() == 0 || drawable.getIntrinsicHeight() == 0) {
        return;
    }

    int drawableWidth = drawable.getIntrinsicWidth();
    int drawableHeight = drawable.getIntrinsicHeight();
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    viewWidth = setViewSize(widthMode, widthSize, drawableWidth);
    viewHeight = setViewSize(heightMode, heightSize, drawableHeight);

    //
    // Set view dimensions
    //
    setMeasuredDimension(viewWidth, viewHeight);

    //
    // Scale image for view
    //
    float scaleX = (float) viewWidth / drawableWidth;
    float scaleY = (float) viewHeight / drawableHeight;
    float scale = Math.min(scaleX, scaleY);

    //
    // Center the image
    //
    float redundantYSpace = viewHeight - (scale * drawableHeight);
    float redundantXSpace = viewWidth - (scale * drawableWidth);
    matchViewWidth = viewWidth - redundantXSpace;
    matchViewHeight = viewHeight - redundantYSpace;

    if (normalizedScale == 1) {
        //
        // Stretch and center image to fit view
        //
        matrix.setScale(scale, scale);
        matrix.postTranslate(redundantXSpace / 2, redundantYSpace / 2);

    } else {
        prevMatrix.getValues(m);

        //
        // Rescale Matrix after rotation
        //
        m[Matrix.MSCALE_X] = matchViewWidth / drawableWidth * normalizedScale;
        m[Matrix.MSCALE_Y] = matchViewHeight / drawableHeight * normalizedScale;

        //
        // TransX and TransY from previous matrix
        //
        float transX = m[Matrix.MTRANS_X];
        float transY = m[Matrix.MTRANS_Y];

        //
        // Width
        //
        float prevActualWidth = prevMatchViewWidth * normalizedScale;
        float actualWidth = getImageWidth();
        translateMatrixAfterRotate(Matrix.MTRANS_X, transX, prevActualWidth, actualWidth, prevViewWidth, viewWidth, drawableWidth);

        //
        // Height
        //
        float prevActualHeight = prevMatchViewHeight * normalizedScale;
        float actualHeight = getImageHeight();
        translateMatrixAfterRotate(Matrix.MTRANS_Y, transY, prevActualHeight, actualHeight, prevViewHeight, viewHeight, drawableHeight);

        //
        // Set the matrix to the adjusted scale and translate values.
        //
        matrix.setValues(m);
    }
    fixTrans();
    setImageMatrix(matrix);
}
 
源代码20 项目: FragmentRigger   文件: ImageViewUtil.java
/**
 * 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;
}