how to use mapPoints?I need draw points(coordinates) depending matrix movement

与世无争的帅哥 提交于 2019-12-10 10:55:30

问题


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

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

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

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 for your help and your time, if you need more code, just say it


回答1:


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

(mapPoints convert absolute coordinates to relatives)

Here the 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);
    }

}


来源:https://stackoverflow.com/questions/26713885/how-to-use-mappointsi-need-draw-pointscoordinates-depending-matrix-movement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!