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

The following examples show how to use android.graphics.Matrix#set() . 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: ViewPortHandler.java    From JNChartDemo with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: ImageActivity.java    From letv with Apache License 2.0 6 votes vote down vote up
private void c() {
    float width = (float) this.q.width();
    Matrix imageMatrix = this.e.getImageMatrix();
    float[] fArr = new float[9];
    imageMatrix.getValues(fArr);
    float f = fArr[2];
    float f2 = fArr[5];
    float f3 = fArr[0];
    width = 640.0f / width;
    int i = (int) ((((float) this.q.left) - f) / f3);
    int i2 = (int) ((((float) this.q.top) - f2) / f3);
    Matrix matrix = new Matrix();
    matrix.set(imageMatrix);
    matrix.postScale(width, width);
    int i3 = (int) (650.0f / f3);
    Bitmap createBitmap = Bitmap.createBitmap(this.s, i, i2, Math.min(this.s.getWidth() - i, i3), Math.min(this.s.getHeight() - i2, i3), matrix, true);
    Bitmap createBitmap2 = Bitmap.createBitmap(createBitmap, 0, 0, 640, 640);
    createBitmap.recycle();
    a(createBitmap2);
}
 
Example 3
Source File: PinchImageView.java    From UGank with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取某个矩阵的copy
 */
public static Matrix matrixTake(Matrix matrix) {
    Matrix result = mMatrixPool.take();
    if (matrix != null) {
        result.set(matrix);
    }
    return result;
}
 
Example 4
Source File: PinchImageView.java    From FaceT with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 获取某个矩阵的copy
 */
public static Matrix matrixTake(Matrix matrix) {
    Matrix result = mMatrixPool.take();
    if (matrix != null) {
        result.set(matrix);
    }
    return result;
}
 
Example 5
Source File: BubbleDrawable.java    From SocketIO_Chat_APP with MIT License 5 votes vote down vote up
private void setUpShaderMatrix() {
    Matrix mShaderMatrix = new Matrix();
    mShaderMatrix.set(null);
    int mBitmapWidth = bubbleBitmap.getWidth();
    int mBitmapHeight = bubbleBitmap.getHeight();
    float scaleX = getIntrinsicWidth() / (float) mBitmapWidth;
    float scaleY = getIntrinsicHeight() / (float) mBitmapHeight;
    mShaderMatrix.postScale(scaleX, scaleY);
    mShaderMatrix.postTranslate(mRect.left, mRect.top);
    mBitmapShader.setLocalMatrix(mShaderMatrix);
}
 
Example 6
Source File: ViewTransformer.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * トランスフォームマトリックスのコピーを取得
 * @param transform nullなら内部で新しいMatrixを生成して返す, nullでなければコピーする
 * @return
 */
@NonNull
@Override
public Matrix getTransform(@Nullable final Matrix transform) {
	if (transform != null) {
		transform.set(mTransform);
		return transform;
	} else {
		return new Matrix(mTransform);
	}
}
 
Example 7
Source File: PhotoViewAttacher.java    From ImagePicker with Apache License 2.0 4 votes vote down vote up
/**
 * Get the current support matrix
 */
public void getSuppMatrix(Matrix matrix)
{
    matrix.set(mSuppMatrix);
}
 
Example 8
Source File: CanvasMatrix.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
void getCurrent(@NonNull Matrix into) {
  into.set(canvasMatrix);
}
 
Example 9
Source File: AndroidGraphics.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public void drawPath(Path p, Stroke stroke) {
    if (maxBitmapSize == 0) {
        maxBitmapSize = Integer.parseInt(Display.getInstance().getProperty("android.maxBitmapSize", Math.max(CN.getDisplayWidth(), CN.getDisplayHeight())*2+""));
    }
    
    paint.setStyle(Paint.Style.STROKE);
    Stroke old = setStroke(stroke);
    //canvas.save();
    //System.out.println("Drawing path with transform "+getTransform());
    //applyTransform();
    //System.out.println("Transform semaphore "+transformSemaphore);
    if (getTransform().isIdentity()) {
        canvas.drawPath(p, paint);
    } else {
        RectF bounds = new RectF();
        p.computeBounds(bounds, false);
        Path p2 = new Path();
        p.transform(getTransformMatrix(), p2);
        RectF bounds2 = new RectF();
        p2.computeBounds(bounds2, false);
        float b2w = bounds2.width();
        float bw = bounds.width();
        float bw2 = Math.max(1, b2w) / Math.max(1, bw);
        float bh2 = Math.max(1, bounds2.height())/Math.max(1, bounds.height());
        float ratio = Math.max(bw2, bh2);
        if (ratio > 2 && !isMutableImageGraphics && bounds2.width() <= maxBitmapSize && bounds2.height() <= maxBitmapSize) {
            // If the canvas is hardware accelerated, then it will rasterize the path
            // first, then apply the transform which leads to blurry paths if the transform does
            // significant scaling.
            // In such cases, we
            float strokeWidthUpperBound = ratio * stroke.getLineWidth();
            int ww = Math.max(1, (int)(bounds2.width()+2*strokeWidthUpperBound));
            int hh = Math.max(1, (int)(bounds2.height()+2*strokeWidthUpperBound));
            Bitmap nativeBuffer = Bitmap.createBitmap(ww, hh, Bitmap.Config.ARGB_8888);
            //int restorePoint = canvas.saveLayer(bounds2, paint, Canvas.ALL_SAVE_FLAG);
            Canvas c = new Canvas(nativeBuffer);
            Matrix translateM = new Matrix();
            translateM.set(getTransformMatrix());
            translateM.postTranslate(-bounds2.left + strokeWidthUpperBound, -bounds2.top + strokeWidthUpperBound);
            c.concat(translateM);
            c.drawPath(p, paint);
            canvas.drawBitmap(nativeBuffer, bounds2.left-strokeWidthUpperBound, bounds2.top-strokeWidthUpperBound, paint);

        } else {
            canvas.save();
            applyTransform();
            canvas.drawPath(p, paint);
            unapplyTransform();
            canvas.restore();
        }
    }
    setStroke(old);
}
 
Example 10
Source File: PhotoViewAttacher.java    From Matisse-Kotlin with Apache License 2.0 4 votes vote down vote up
/**
 * Get the current support matrix
 */
public void getSuppMatrix(Matrix matrix) {
    matrix.set(mSuppMatrix);
}
 
Example 11
Source File: ViewPortHandler.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
public void zoom(float scaleX, float scaleY, Matrix outputMatrix) {
    outputMatrix.reset();
    outputMatrix.set(mMatrixTouch);
    outputMatrix.postScale(scaleX, scaleY);
}
 
Example 12
Source File: CropState.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public Matrix getMatrix() {
    Matrix m = new Matrix();
    m.set(matrix);
    return m;
}
 
Example 13
Source File: CropView.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private Matrix getMatrix() {
    Matrix m = new Matrix();
    m.set(matrix);
    return m;
}
 
Example 14
Source File: ViewPortHandler.java    From Stayfit with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the scale factor to the specified values. x and y is pivot.
 *
 * @param scaleX
 * @param scaleY
 * @param x
 * @param y
 * @return
 */
public Matrix setZoom(float scaleX, float scaleY, float x, float y) {

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

    save.setScale(scaleX, scaleY, x, y);

    return save;
}
 
Example 15
Source File: ViewPortHandler.java    From Stayfit with Apache License 2.0 3 votes vote down vote up
/**
 * Post-translates to the specified points.
 *
 * @param transformedPts
 * @return
 */
public Matrix translate(final float[] transformedPts) {

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

    final float x = transformedPts[0] - offsetLeft();
    final float y = transformedPts[1] - offsetTop();

    save.postTranslate(-x, -y);

    return save;
}
 
Example 16
Source File: ViewPortHandler.java    From JNChartDemo with Apache License 2.0 3 votes vote down vote up
/**
 * Zooms in by 1.4f, x and y are the coordinates (in pixels) of the zoom
 * center.
 *
 * @param x
 * @param y
 */
public Matrix zoomIn(float x, float y) {

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

    save.postScale(1.4f, 1.4f, x, y);

    return save;
}
 
Example 17
Source File: ViewPortHandler.java    From Ticket-Analysis with MIT License 3 votes vote down vote up
/**
 * Sets the scale factor to the specified values. x and y is pivot.
 *
 * @param scaleX
 * @param scaleY
 * @param x
 * @param y
 * @return
 */
public Matrix setZoom(float scaleX, float scaleY, float x, float y) {

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

    save.setScale(scaleX, scaleY, x, y);

    return save;
}
 
Example 18
Source File: ViewPortHandler.java    From Stayfit with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the scale factor to the specified values.
 *
 * @param scaleX
 * @param scaleY
 * @return
 */
public Matrix setZoom(float scaleX, float scaleY) {

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

    save.setScale(scaleX, scaleY);

    return save;
}
 
Example 19
Source File: ViewPortHandler.java    From NetKnight with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the scale factor to the specified values. x and y is pivot.
 *
 * @param scaleX
 * @param scaleY
 * @param x
 * @param y
 * @return
 */
public Matrix setZoom(float scaleX, float scaleY, float x, float y) {

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

    save.setScale(scaleX, scaleY, x, y);

    return save;
}
 
Example 20
Source File: PhotoViewAttacher.java    From Mysplash with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Get the display matrix
 *
 * @param matrix target matrix to copy to
 */
public void getDisplayMatrix(Matrix matrix) {
    matrix.set(getDrawMatrix());
}