Draw something on bitmap which can rotate,zoom and drag in Andorid
<p>I find and improve a code that can rotate,zoom and drag with fingers. The code is shown below:</p>

<pre><code>//imports, definitions... 
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        image = (ImageView) findViewById(R.id.imageView);
        image.setOnTouchListener(this);

        btnAdd = (Button) findViewById(R.id.btnAdd);
        btnAdd.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String url = "http://www.queness.com/resources/images/png/apple_ex.png";

                AsyncTask&lt;String,Void,ByteArrayBuffer&gt; connection=new UrlFetchData().execute(url);
                try {
                    baf=connection.get();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }

                byteArray =  baf.toByteArray();
                bmpTempResim = BitmapFactory.decodeByteArray(byteArray, 0 , byteArray.length);
                bmpResim = bmpTempResim.copy(Bitmap.Config.ARGB_8888, true);
                image.setImageBitmap(bmpResim);             
            }
        });

        btnToggleRotate = (ToggleButton) findViewById(R.id.btnToggleRotate);
        btnToggleRotate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View image) {   
            }
        });
        btnToggleLenght = (ToggleButton) findViewById(R.id.btnToggleLenght);
        btnToggleLenght.setOnClickListener(new View.OnClickListener() { 
            @Override
            public void onClick(View image) {
                if(btnToggleLenght.isChecked()){
                    canvas = new Canvas(bmpResim);
                    paint = new Paint();
                    paint.setColor(Color.RED);
                }
            }
        });
        txtViewLenght = (TextView) findViewById(R.id.textViewLenght);
    }
    /** Handle onTouch event */
    @Override
    public boolean onTouch(View view, MotionEvent event) {
        this.image = (ImageView) view;
        int height = image.getDrawable().getIntrinsicHeight();
        int width =  image.getDrawable().getIntrinsicWidth();

        switch (event.getAction() &amp; MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:

            startPoint.set(event.getX(), event.getY());
                if(btnToggleRotate.isChecked()){
                    mode = ROTATE;
                    savedMatrix.set(matrix);
                }
                else if(btnToggleLenght.isChecked()) {
                    mode = DRAWLINE;
                }
                else {
                    mode = DRAG;
                    savedMatrix.set(matrix);
                }
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            oldDist = spacing(event);
            if (oldDist &gt; 10f) {
                savedMatrix.set(matrix);
                findMidPoint(midPoint, event);
                mode = ZOOM;
            }
            break;
        case MotionEvent.ACTION_UP:
            endPoint.set(event.getX(), event.getY());
         if(mode == DRAWLINE){
                canvas.drawCircle(startPoint.x, startPoint.y, 10, paint);
                canvas.drawCircle(endPoint.x, endPoint.y, 10, paint);
                image.invalidate();
                float x =  endPoint.x - startPoint.x;
                float y =  endPoint.y - startPoint.y;
                float z = FloatMath.sqrt(x * x + y * y);
                txtViewLenght.setText("Lenght = " + z * 2.54 / 96 + " cm");
            }
            break;
        case MotionEvent.ACTION_POINTER_UP:
            mode = NONE;
            break;
        case MotionEvent.ACTION_MOVE:
            if (mode == DRAG) {
                matrix.set(savedMatrix);
                matrix.postTranslate(event.getX() - startPoint.x,
                        event.getY() - startPoint.y);

            }
            else if (mode == ZOOM) {
                float newDist = spacing(event);
                if (newDist &gt; 10f) {
                    matrix.set(savedMatrix);
                    float scale = newDist / oldDist;
                    matrix.postScale(scale, scale, midPoint.x, midPoint.y);
                }
            }
            else if(mode == ROTATE){
                centerX = endPoint.x;
                centerY = endPoint.y;   
                degree = findDegree(event, centerX, centerY);
                matrix.set(savedMatrix);
                matrix.preRotate(degree,width/2,height/2);
            }
            else if(mode == DRAWLINE){

            }
            break;
        }
        image.setImageMatrix(matrix);
        return true; // indicate event was handled
    }
    /** Calculate the space between the first two fingers */
    private float spacing(MotionEvent event) {
        //calculations..
    }
    /** Calculate the mid point of the first two fingers */
    private void findMidPoint(PointF point, MotionEvent event) {
        //calculations..
    }
    /** Calculate degree */
    private float findDegree(MotionEvent event, float x, float y){
        //calculations..
    }
</code></pre>

<p>So; here is my problem: When I try to calculate lenght, also draw two point to show on screen, where finger is pushed and up. Because I handle my zoom-move-rotate operations on matrix, have some problem about drawing. For example; I drag image two cm right. if I try to take lenght with my finger that shown as black points, my points is shown two cm right. 
<a href="http://imageshack.us/photo/my-images/405/ekranas.png/" rel="nofollow">http://imageshack.us/photo/my-images/405/ekranas.png/</a></p>

<p>How can I handle this problem? Hopefully, i can tell you my problem. Please help me!! </p>
