获取坐标和宽/高从矩阵 [英] Getting coordinates and width/height from a matrix

查看:113
本文介绍了获取坐标和宽/高从矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个媒体播放器的Andr​​oid平台以及我尝试添加的功能之一是拖动和捏缩放图像的能力。

I'm trying to make a media player for the Android platform and one of the features I'm trying to add is the ability to drag and pinch-zoom pictures.

我遇到的问题是我复制这个code从你好,Android的编辑。 3:

The problem I'm having is I copied this code from "Hello, Android" ed. 3:

@Override
public boolean onTouch(View v, MotionEvent event) {
ImageView view = (ImageView) v;
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
    savedMatrix.set(matrix);
    start.set(event.getX(), event.getY());
    mode = DRAG;
    break;
case MotionEvent.ACTION_POINTER_DOWN:
    oldDist = spacing(event);
    if (oldDist > 10f) {
        savedMatrix.set(matrix);
        midPoint(mid, event);
        mode = ZOOM;
    }
    break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
    mode = NONE;
    break;
case MotionEvent.ACTION_MOVE:
    if (mode == DRAG) {
        matrix.set(savedMatrix);
        matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
    }
    else if (mode == ZOOM) {
        float newDist = spacing(event);
        if (newDist > 10f) {
            matrix.set(savedMatrix);
            float scale = newDist / oldDist;
            matrix.postScale(scale, scale, mid.x, mid.y);
        }
    }
    break;
}
view.setImageMatrix(matrix);

这code段不正是我想要的,但我需要的纯X,Y坐标和图像,而不是矩阵的宽度/高度。

This code snippet does exactly what I want, but I need the pure X,Y coordinates and the width/height of the picture instead of the matrix.

有谁知道如何更改矩阵X,Y坐标,宽度和高度?

Does anyone know how to change the matrix to X, Y coordinates and the width and height?

推荐答案

原来,解决方法很简单:

Turns out the solution is simple:

float[] values = new float[9];
matrix.getValues(values);
globalX = values[Matrix.MTRANS_X];
globalY = values[Matrix.MTRANS_Y];
width = values[Matrix.MSCALE_X]*imageWidth;
height = values[Matrix.MSCALE_Y]*imageHeight;

这篇关于获取坐标和宽/高从矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆