gpt4 book ai didi

android - 根据矩阵将触摸值转换为点

转载 作者:太空狗 更新时间:2023-10-29 16:23:19 27 4
gpt4 key购买 nike

我正在按矩阵平移和缩放图像,现在我有了矩阵值。所以从矩阵值我想将我的触摸坐标转换为它的位置,这是通过矩阵获得的。那我该怎么做呢?请尽快帮助我。

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);

为了得到图像上的点,我得到了矩阵 image 的踪迹,这是方法:

    @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);
}

关于android - 根据矩阵将触摸值转换为点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9016230/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com