PhotoView - 获取相对于缩放图像的单元格/触摸坐标

时间:2018-03-18 18:44:34

标签: java android android-canvas android-bitmap

enter image description here

基本上,我将背景图像添加到Imageview并在位图上绘制了一些线条。 gSeed是每个细胞的大小。现在我用Touch Listener计算了每个单元格的索引。但是当我使用photoView时,我无法使用以下触摸侦听器。需要帮助将此功能与photoview一起使用,并且在缩放时它应该给出imageView的坐标而不是屏幕,因为在Zoom上它将显示原始图像单元格细节。

mImageView.setOnTouchListener(new View.OnTouchListener(){

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            float x = motionEvent.getX();
            float y = motionEvent.getY();

            String message = String.format("Coordinates: (%.2f,%.2f)",x,y);

            int Y = (int) Math.floor(x/gSeed);
            int X = (int) Math.floor(y/gSeed);

            int p = X*6+Y;;

            //gSeed values = no.of columns
            //200 = 6
            //190 = 6
            //180 = 6

            //170 = 7
            //160 = 7

            //150 = 8
            //140 = 8

            //130 = 9
            //120 = 9

            //110 = 10
            //100 = 11
            //90 = 12
            //80 = 14
            //70 = 16
            //60 = 18
            //50 = 22
            if(gSeed == 200 || gSeed == 190 || gSeed == 180){
                p = X*6+Y;
            }
            else if(gSeed == 170 || gSeed == 160){
                p = X*7+Y;
            }
            else if(gSeed == 150 || gSeed == 140){
                p = X*8+Y;
            }
            else if(gSeed == 130 || gSeed == 120){
                p = X*9+Y;
            }
            else if(gSeed == 110){
                p = X*10+Y;
            }
            else if(gSeed == 100){
                p = X*11+Y;
            }
            else if(gSeed == 90){
                p = X*12+Y;
            }
            else if(gSeed == 80){
                p = X*14+Y;
            }
            else if(gSeed == 70){
                p = X*16+Y;
            }
            else if(gSeed == 60){
                p = X*18+Y;
            }
            else if(gSeed == 50){
                p = X*22+Y;
            }


            System.out.println(message+" Cell#/; "+ p);
            Toast.makeText(Train.this,message+" Cell#/; "+ p+" x:"+X+" y:"+Y, Toast.LENGTH_SHORT).show();


            return false;
        }
    });

0 个答案:

没有答案
相关问题