1

Hi, This is my code for zoom and drag image. Now I want to add image when touch the zoom image but I did not get accurate x and y coordinates.

Please help me what is missing in my code.

View.OnTouchListener mTouchListener = new OnTouchListener() {

    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());
            Log.d(TAG, "mode=DRAG");
            mode = DRAG;

            if (flag) {     
//When mark button click then flag is true means add another image to display image when touch

                mImageView.setImageBitmap(combineImages(mSave, mIcon, event.getX(),
                        event.getY()));
                mSave = combineImages(mSave, mIcon, event.getX(), event.getY());
            }
            break;
        case MotionEvent.ACTION_POINTER_DOWN:

            oldDist = spacing(event);
            if (oldDist > 10f) {
                savedMatrix.set(matrix);
                midPoint(mid, event);
                mode = ZOOM;
                Log.d(TAG, "mode=ZOOM");
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
            mode = NONE;
            Log.d(TAG, "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);
                    scale = newDist / oldDist;
                    matrix.postScale(scale, scale, mid.x, mid.y);
                }
            }
            break;
        }
        view.setImageMatrix(matrix);
        return true;
    }
};

I also refer this link but can't understand much more..

Please give me suggestion what I am doing wrong.

Community
  • 1
  • 1
kalpana c
  • 2,739
  • 3
  • 27
  • 47
  • 1
    are you able to zoom in /out ? – Shankar Agarwal Apr 12 '12 at 11:23
  • @Agarwal: I have tested this code. This code work fine for zoom in/out, but problem occurs when we do zoom and click on screen then, accurate x,y co-ordinates not return by Motion event. – Hitesh Patel Apr 12 '12 at 11:28
  • 2
    yes i am able to zoom in and out and also scroll but when zoom in then i want to x and y coordinate and attach new image there. – kalpana c Apr 12 '12 at 11:31
  • 1
    [Take a look][1] [1]: http://stackoverflow.com/questions/10039545/zoom-image-with-effect-ontouch-android/10039709#10039709 I posted a code which can help you... – Suvam Roy Apr 12 '12 at 11:33

0 Answers0