Java Code Examples for android.graphics.Matrix.MTRANS_Y

The following are Jave code examples for showing how to use MTRANS_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.
+ Save this method
Example 1
Project: GitHub   File: ViewPortHandler.java   View Source Code 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 2
Project: yphoto   File: TouchImageView.java   View Source Code Vote up 6 votes
/**
 * This function will transform the coordinates in the touch event to the coordinate
 * system of the drawable that the imageview contain
 * @param x x-coordinate of touch event
 * @param y y-coordinate of touch event
 * @param clipToBitmap Touch event may occur within view, but outside image content. True, to clip return value
 * 			to the bounds of the bitmap size.
 * @return Coordinates of the point touched, in the coordinate system of the original drawable.
 */
private PointF transformCoordTouchToBitmap(float x, float y, boolean clipToBitmap) {
    matrix.getValues(m);
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float transX = m[Matrix.MTRANS_X];
    float transY = m[Matrix.MTRANS_Y];
    float finalX = ((x - transX) * origW) / getImageWidth();
    float finalY = ((y - transY) * origH) / getImageHeight();

    if (clipToBitmap) {
        finalX = Math.min(Math.max(finalX, 0), origW);
        finalY = Math.min(Math.max(finalY, 0), origH);
    }

    return new PointF(finalX , finalY);
}
 
Example 3
Project: spinify_android   File: TouchImageView.java   View Source Code Vote up 6 votes
/**
 * This function will transform the coordinates in the touch event to the coordinate
 * system of the drawable that the imageview contain
 *
 * @param x            x-coordinate of touch event
 * @param y            y-coordinate of touch event
 * @param clipToBitmap Touch event may occur within view, but outside image content. True, to clip return value
 *                     to the bounds of the bitmap size.
 * @return Coordinates of the point touched, in the coordinate system of the original drawable.
 */
private PointF transformCoordTouchToBitmap(float x, float y, boolean clipToBitmap) {
    matrix.getValues(m);
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float transX = m[Matrix.MTRANS_X];
    float transY = m[Matrix.MTRANS_Y];
    float finalX = ((x - transX) * origW) / getImageWidth();
    float finalY = ((y - transY) * origH) / getImageHeight();

    if (clipToBitmap) {
        finalX = Math.min(Math.max(finalX, 0), origW);
        finalY = Math.min(Math.max(finalY, 0), origH);
    }

    return new PointF(finalX, finalY);
}
 
Example 4
Project: PinchToZoom   File: ImageViewerCorrector.java   View Source Code Vote up 6 votes
@Override
public void performAbsoluteCorrections() {
	super.performAbsoluteCorrections();
	
	// Calculate the image's new dimensions
	updateScaledImageDimensions();

	// Correct scale
	//values[Matrix.MSCALE_X] = values[Matrix.MSCALE_Y] = correctAbsolute(Matrix.MSCALE_X, values[Matrix.MSCALE_X]);

	// Correct the translations
	float[] values = getValues();
	values[Matrix.MTRANS_X] = correctAbsolute(Matrix.MTRANS_X, values[Matrix.MTRANS_X]);
	values[Matrix.MTRANS_Y] = correctAbsolute(Matrix.MTRANS_Y, values[Matrix.MTRANS_Y]);

	// Update the matrix
	getMatrix().setValues(values);
}
 
Example 5
Project: chat-sdk-android-push-firebase   File: TouchImageView.java   View Source Code Vote up 6 votes
/**
 * Set zoom to the specified scale. Image will be centered around the point
 * (focusX, focusY). These floats range from 0 to 1 and denote the focus point
 * as a fraction from the left and top of the view. For example, the top left 
 * corner of the image would be (0, 0). And the bottom right corner would be (1, 1).
 * @param scale
 * @param focusX
 * @param focusY
 * @param scaleType
 */
public void setZoom(float scale, float focusX, float focusY, ScaleType scaleType) {
	//
	// setZoom can be called before the image is on the screen, but at this point, 
	// image and view sizes have not yet been calculated in onMeasure. Thus, we should
	// delay calling setZoom until the view has been measured.
	//
	if (!onDrawReady) {
		delayedZoomVariables = new ZoomVariables(scale, focusX, focusY, scaleType);
		return;
	}
	
	if (scaleType != mScaleType) {
		setScaleType(scaleType);
	}
	resetZoom();
	scaleImage(scale, viewWidth / 2, viewHeight / 2, true);
	matrix.getValues(m);
	m[Matrix.MTRANS_X] = -((focusX * getImageWidth()) - (viewWidth * 0.5f));
	m[Matrix.MTRANS_Y] = -((focusY * getImageHeight()) - (viewHeight * 0.5f));
	matrix.setValues(m);
	fixTrans();
	setImageMatrix(matrix);
}
 
Example 6
Project: Hotspot-master-devp   File: MatrixImageView.java   View Source Code Vote up 6 votes
/**
 *   初始化模板Matrix和图片的其他数据
 */
private void initData() {
    //设置完图片后,获取该图片的坐标变换矩阵
    mMatrix.set(getImageMatrix());
    float[] values=new float[9];
    mMatrix.getValues(values);
    //图片宽度为屏幕宽度除缩放倍数
    //要考虑长图,去掉了两边的空白
    mImageWidth=(getWidth()-values[Matrix.MTRANS_X]*2)/values[Matrix.MSCALE_X];
    mImageHeight=(getHeight()-values[Matrix.MTRANS_Y]*2)/values[Matrix.MSCALE_Y];
    mScale=values[Matrix.MSCALE_X];

    initX = values[Matrix.MTRANS_X];
    initY = values[Matrix.MTRANS_Y];
    currentBitmapWidth = mImageWidth*values[Matrix.MSCALE_X];
    currentBitmapHeight = mImageHeight*values[Matrix.MSCALE_Y];

}
 
Example 7
Project: LongImageCamera   File: TouchImageView.java   View Source Code Vote up 5 votes
/**
 * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
 * drawable's coordinate system to the view's coordinate system.
 * @param bx x-coordinate in original bitmap coordinate system
 * @param by y-coordinate in original bitmap coordinate system
 * @return Coordinates of the point in the view's coordinate system.
 */
private PointF transformCoordBitmapToTouch(float bx, float by) {
    matrix.getValues(m);        
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float px = bx / origW;
    float py = by / origH;
    float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
    float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
    return new PointF(finalX , finalY);
}
 
Example 8
Project: Swface   File: PictureUtil.java   View Source Code Vote up 5 votes
public static Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree)
{
	Matrix m = new Matrix();
	m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2);
	float targetX, targetY;
	if (orientationDegree == 90) {
		targetX = bm.getHeight();
		targetY = 0;
	} else {
		targetX = bm.getHeight();
		targetY = bm.getWidth();
	}

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

	float x1 = values[Matrix.MTRANS_X];
	float y1 = values[Matrix.MTRANS_Y];

	m.postTranslate(targetX - x1, targetY - y1);
	Bitmap bm1 = Bitmap.createBitmap(bm.getHeight(), bm.getWidth(), Bitmap.Config.ARGB_8888);
	Paint paint = new Paint();
	Canvas canvas = new Canvas(bm1);
	canvas.drawBitmap(bm, m, paint);

	return bm1;
}
 
Example 9
Project: Sega   File: TouchImageView.java   View Source Code Vote up 5 votes
/**
 * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
 * drawable's coordinate system to the view's coordinate system.
 *
 * @param bx x-coordinate in original bitmap coordinate system
 * @param by y-coordinate in original bitmap coordinate system
 * @return Coordinates of the point in the view's coordinate system.
 */
private PointF transformCoordBitmapToTouch(float bx, float by) {
    matrix.getValues(m);
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float px = bx / origW;
    float py = by / origH;
    float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
    float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
    return new PointF(finalX, finalY);
}
 
Example 10
Project: Expert-Android-Programming   File: TouchImageView.java   View Source Code Vote up 5 votes
/**
 * When transitioning from zooming from focus to zoom from center (or vice versa)
 * the image can become unaligned within the view. This is apparent when zooming
 * quickly. When the content size is less than the view size, the content will often
 * be centered incorrectly within the view. fixScaleTrans first calls fixTrans() and
 * then makes sure the image is centered correctly within the view.
 */
private void fixScaleTrans() {
    fixTrans();
    matrix.getValues(m);
    if (getImageWidth() < viewWidth) {
        m[Matrix.MTRANS_X] = (viewWidth - getImageWidth()) / 2;
    }

    if (getImageHeight() < viewHeight) {
        m[Matrix.MTRANS_Y] = (viewHeight - getImageHeight()) / 2;
    }
    matrix.setValues(m);
}
 
Example 11
Project: yphoto   File: TouchImageView.java   View Source Code Vote up 5 votes
/**
 * When transitioning from zooming from focus to zoom from center (or vice versa)
 * the image can become unaligned within the view. This is apparent when zooming
 * quickly. When the content size is less than the view size, the content will often
 * be centered incorrectly within the view. fixScaleTrans first calls fixTrans() and
 * then makes sure the image is centered correctly within the view.
 */
private void fixScaleTrans() {
    fixTrans();
    matrix.getValues(m);
    if (getImageWidth() < viewWidth) {
        m[Matrix.MTRANS_X] = (viewWidth - getImageWidth()) / 2;
    }

    if (getImageHeight() < viewHeight) {
        m[Matrix.MTRANS_Y] = (viewHeight - getImageHeight()) / 2;
    }
    matrix.setValues(m);
}
 
Example 12
Project: Hitalk   File: BGAQRCodeUtil.java   View Source Code Vote up 5 votes
public static Bitmap adjustPhotoRotation(Bitmap inputBitmap, int orientationDegree) {
    if (inputBitmap == null) {
        return null;
    }

    Matrix matrix = new Matrix();
    matrix.setRotate(orientationDegree, (float) inputBitmap.getWidth() / 2, (float) inputBitmap.getHeight() / 2);
    float outputX, outputY;
    if (orientationDegree == 90) {
        outputX = inputBitmap.getHeight();
        outputY = 0;
    } else {
        outputX = inputBitmap.getHeight();
        outputY = inputBitmap.getWidth();
    }

    final float[] values = new float[9];
    matrix.getValues(values);
    float x1 = values[Matrix.MTRANS_X];
    float y1 = values[Matrix.MTRANS_Y];
    matrix.postTranslate(outputX - x1, outputY - y1);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap.getHeight(), inputBitmap.getWidth(), Bitmap.Config.ARGB_8888);
    Paint paint = new Paint();
    Canvas canvas = new Canvas(outputBitmap);
    canvas.drawBitmap(inputBitmap, matrix, paint);
    return outputBitmap;
}
 
Example 13
Project: cordova-plugin-video-picture-preview-picker-V2   File: TouchImageView.java   View Source Code Vote up 5 votes
/**
 * Performs boundary checking and fixes the image matrix if it is out of
 * bounds.
 */
private void fixTrans() {
	matrix.getValues(m);
	float transX = m[Matrix.MTRANS_X];
	float transY = m[Matrix.MTRANS_Y];

	float fixTransX = getFixTrans(transX, viewWidth, getImageWidth());
	float fixTransY = getFixTrans(transY, viewHeight, getImageHeight());

	if (fixTransX != 0 || fixTransY != 0) {
		matrix.postTranslate(fixTransX, fixTransY);
	}
}
 
Example 14
Project: Programmers   File: TouchImageView.java   View Source Code Vote up 5 votes
/**
 * When transitioning from zooming from focus to zoom from center (or vice versa)
 * the image can become unaligned within the view. This is apparent when zooming
 * quickly. When the content size is less than the view size, the content will often
 * be centered incorrectly within the view. fixScaleTrans first calls fixTrans() and
 * then makes sure the image is centered correctly within the view.
 */
private void fixScaleTrans() {
    fixTrans();
    matrix.getValues(m);
    if (getImageWidth() < viewWidth) {
        m[Matrix.MTRANS_X] = (viewWidth - getImageWidth()) / 2;
    }

    if (getImageHeight() < viewHeight) {
        m[Matrix.MTRANS_Y] = (viewHeight - getImageHeight()) / 2;
    }
    matrix.setValues(m);
}
 
Example 15
Project: LongImageCamera   File: TouchImageView.java   View Source Code Vote up 5 votes
Fling(int velocityX, int velocityY) {
	setState(State.FLING);
	scroller = new CompatScroller(context);
	matrix.getValues(m);
	
	int startX = (int) m[Matrix.MTRANS_X];
	int startY = (int) m[Matrix.MTRANS_Y];
	int minX, maxX, minY, maxY;
	
	if (getImageWidth() > viewWidth) {
		minX = viewWidth - (int) getImageWidth();
		maxX = 0;
		
	} else {
		minX = maxX = startX;
	}
	
	if (getImageHeight() > viewHeight) {
		minY = viewHeight - (int) getImageHeight();
		maxY = 0;
		
	} else {
		minY = maxY = startY;
	}
	
	scroller.fling(startX, startY, (int) velocityX, (int) velocityY, minX,
               maxX, minY, maxY);
	currX = startX;
	currY = startY;
}
 
Example 16
Project: social-app-android   File: TouchImageView.java   View Source Code Vote up 5 votes
/**
 * Performs boundary checking and fixes the image matrix if it
 * is out of bounds.
 */
private void fixTrans() {
    matrix.getValues(m);
    float transX = m[Matrix.MTRANS_X];
    float transY = m[Matrix.MTRANS_Y];

    float fixTransX = getFixTrans(transX, viewWidth, getImageWidth());
    float fixTransY = getFixTrans(transY, viewHeight, getImageHeight());

    if (fixTransX != 0 || fixTransY != 0) {
        matrix.postTranslate(fixTransX, fixTransY);
    }
}
 
Example 17
Project: Hotspot-master-devp   File: MatrixImageView.java   View Source Code 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 18
Project: Monolith   File: TouchImageView.java   View Source Code Vote up 5 votes
/**
 * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
 * drawable's coordinate system to the view's coordinate system.
 * @param bx x-coordinate in original bitmap coordinate system
 * @param by y-coordinate in original bitmap coordinate system
 * @return Coordinates of the point in the view's coordinate system.
 */
private PointF transformCoordBitmapToTouch(float bx, float by) {
    matrix.getValues(m);
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float px = bx / origW;
    float py = by / origH;
    float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
    float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
    return new PointF(finalX , finalY);
}
 
Example 19
Project: AndroidBackendlessChat   File: TouchImageView.java   View Source Code Vote up 5 votes
Fling(int velocityX, int velocityY) {
	setState(State.FLING);
	scroller = new CompatScroller(context);
	matrix.getValues(m);
	
	int startX = (int) m[Matrix.MTRANS_X];
	int startY = (int) m[Matrix.MTRANS_Y];
	int minX, maxX, minY, maxY;
	
	if (getImageWidth() > viewWidth) {
		minX = viewWidth - (int) getImageWidth();
		maxX = 0;
		
	} else {
		minX = maxX = startX;
	}
	
	if (getImageHeight() > viewHeight) {
		minY = viewHeight - (int) getImageHeight();
		maxY = 0;
		
	} else {
		minY = maxY = startY;
	}
	
	scroller.fling(startX, startY, (int) velocityX, (int) velocityY, minX,
               maxX, minY, maxY);
	currX = startX;
	currY = startY;
}
 
Example 20
Project: Customerly-Android-SDK   File: TouchImageView.java   View Source Code Vote up 5 votes
/**
 * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
 * drawable's coordinate system to the view's coordinate system.
 * @param bx x-coordinate in original bitmap coordinate system
 * @param by y-coordinate in original bitmap coordinate system
 * @return Coordinates of the point in the view's coordinate system.
 */
private PointF transformCoordBitmapToTouch(float bx, float by) {
    matrix.getValues(m);        
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float px = bx / origW;
    float py = by / origH;
    float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
    float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
    return new PointF(finalX , finalY);
}