本文介绍了如何使用mapPoints?我需要画点(坐标),这取决于基体运动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的ImageView在那里我有一个矩阵,我可以拖动,缩放,现在我可以画画和删除点(坐标)超过它。

I have a custom imageView where i have a matrix and i can drag, zoom and now i can paint and delete points(coordinates)over it too.

问题是:我如何可以移动缩放后点,或拖动矩阵

The problem is: how can i move that points after zoom or drag the matrix

我在(马克保存所有的点和标记都只有2个变量(X,Y)浮定制clases或int对于保存坐标

I have saved all the points in (Mark and Marking are custom clases with just 2 variables(x,y) float or int for save coordinates

static ArrayList <Marking> listaPtos = new ArrayList<Marking>(); 
static ArrayList <Mark> listaMarcas = new ArrayList<Mark>();

我怎么救的坐标?使用mapPoints?我尝试,但我不知道正确的公式

how i save the coordinates? using mapPoints?I try it but i dont know the correct formula

void saveCoordinates(float x, float y){
    Log.i("guardaCoordenadas","de float");
    Mark m = new Mark(x,y);
    listaMarcas.add(m);
    Log.i("marca",""+m.x+"-"+m.y);
    Main.txtCont.setText(x+"-"+y);
    guardaCoordenadas(lastTouchX,lastTouchY);
}
void guardaCoordenadas(int x, int y){
    Log.i("guardaCoordenadas","de int");
    Marking m = new Marking(x,y);
    listaPtos.add(m);
    Log.i("listaPtos0",""+m.x+"-"+m.y);
}

这是我的onDraw

this is my onDraw

public void onDraw(Canvas c){
    Log.d("onDraw","pinta="+pinta);
    c.drawBitmap(bitmap, matrix, paintFondo);
    c.drawPath(path,new Paint());
    if(pinta){
        Log.d("activando","clickPinta");
        //this.setOnTouchListener(null);
        this.setOnTouchListener(clickPinta);
    }
    else{
        Log.d("activando","clickImagen");
        //this.setOnTouchListener(null);
        this.setOnTouchListener(clickImagen);
    }

    if(listaPtos!=null){
        Log.i("pintando",listaPtos.size()+" puntos");
        /*for(Marking mark:listaPtos){              
            c.drawBitmap(cruz, mark.x, mark.y, paintPuntos);
            //c.drawCircle(mark.x, mark.y, 20, new Paint());
        }*/
        for(Mark mark:listaMarcas){ 
            //c.drawBitmap(cruz, mark.x, mark.y, paintPuntos);
            c.drawBitmap(cruz, mark.x, mark.y, new Paint());
        }
    }
}

这是我尝试使用移动点的方法:

and this is the method which i try use for move points:

void moveCoordenadas(float x, float y){
    if (mode==DRAG){
        for (int i=0; i<listaMarcas.size();i++){
            Mark mark = listaMarcas.get(i);
            float [] coor = new float[2];
            coor[0]=mark.x;
            coor[1]=mark.y;
            matrix.mapPoints(coor);
            mark.x=coor[0];
            mark.y=coor[1];
            listaMarcas.set(i, mark);
        }
    }
    if (mode==ZOOM){

    }

}

林与阻力只是想在第一,因为很容易

Im trying just with drag at first because is easier

THX你的帮助,你的时候,如果你需要更多的code,只是说它

thx for your help and your time, if you need more code, just say it

推荐答案

如果有人有同样的问题,我解决它matrix.mapPoints()

If somebody have the same problem, I solve it with matrix.mapPoints()

(mapPoints转换绝对坐标亲戚)

(mapPoints convert absolute coordinates to relatives)

在这里,code:

void moveCoordinates(){
    for (int i=0; i<listaPtos.size();i++){
        Marking pto = listaPtos.get(i);//absolutes coordinates
        Mark mark = listaMarcas.get(i);//relatives coordinates
        float[]coor = new float[2];
        coor[0]=pto.x;
        coor[1]=pto.y;
        matrix.mapPoints(coor);
        mark.setX(coor[0]);
        mark.setY(coor[1]);
        listaMarcas.set(i, mark);
    }

}

这篇关于如何使用mapPoints?我需要画点(坐标),这取决于基体运动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 03:09