Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 基于矩阵将接触值转换为点_Android_Matrix_Android Canvas - Fatal编程技术网

Android 基于矩阵将接触值转换为点

Android 基于矩阵将接触值转换为点,android,matrix,android-canvas,Android,Matrix,Android Canvas,我正在按矩阵转换和缩放图像,现在我有了矩阵值。所以从矩阵值,我想把我的触摸坐标转换成它的位置,这是由矩阵得到的。那我该怎么办呢? 请尽快帮助我 private void drawPoint(float x, float y, float pressure, float width) { // left is tx of matrix // top is ty of matrix float curX = (x - left) / (scale * scale);

我正在按矩阵转换和缩放图像,现在我有了矩阵值。所以从矩阵值,我想把我的触摸坐标转换成它的位置,这是由矩阵得到的。那我该怎么办呢? 请尽快帮助我

private void drawPoint(float x, float y, float pressure, float width) {

 // left is tx of matrix 
     // top is ty of matrix

    float curX = (x - left) / (scale * scale);
    float curY = (y - top) / (scale * scale);

         canvas.drawPoint((curX - left), (curY - top) , mPaint);
}

我知道这是一个老帖子,但我也有同样的问题

我有一个应用矩阵变换的图像,首先我调整它的大小,然后我做一个转换

    image = new Matrix();
    image.setScale(zoom, zoom);

    Paint drawPaint = new Paint();
    drawPaint.setAntiAlias(true);
    drawPaint.setFilterBitmap(true);

    float centerScaledWidth = image_center.x * zoom / 2;
    float centerScaledHeigth = image_center.y * zoom / 2;

    image.postTranslate(screen_center.x -  centerScaledWidth, 
            screen_center.y - centerScaledHeigth);

    canvas.drawBitmap(bmp, image, drawPaint);
为了得到图像上的点,我得到了矩阵图像的轨迹,这是一种方法:

    @Override
    public boolean onTouchEvent(MotionEvent ev) {

            final int action = ev.getAction();

            switch (action & MotionEvent.ACTION_MASK) {

                    case MotionEvent.ACTION_DOWN: {

                        final float x = ev.getX();
                        final float y = ev.getY();

                        float[] pts = {x, y};

                        Matrix m = new Matrix();

                        // This is the magic, I set the new matrix m 
                        // as the inverse of 
                        // the matrix applied to the image
                        image.invert(m);

                        // transform the points using the inverse matrix
                        m.mapPoints(pts);

                        // do what you have to do
                        .......

                        Log.i("transformed", pts[0] +" "+pts[1]);

                        break;
                    }

            }

    return super.onTouchEvent(ev);
}

这很有效,非常感谢。似乎你必须非常聪明才能在谷歌工作和为谷歌发展O