2

I am trying to make an application in which i can zoom in and draw some thing on the image i have used following link to make a zoomable image view which is working fine zoom functionality for images

now the problem is that i dont know how to scale and translate whatever i am drawing on my canvas to the image size when it is zoomed out. following is the onDraw() function. i have recorded the touch points added them into a list and in this onDraw() function of my view i am retrieving those points but these points are relative to screen . i have to translate and scale it according to the image operation(in case of zoom in/out of the image) .

 protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

if(mMarkers!=null)
{
for(Marker m : mMarkers) {
    // draw the marker
     Log.v("IP","position"+ m.x+"    "+ m.y);
    Paint paint=new Paint();
    paint.setARGB(255, 2, 255, 2);
    canvas.drawText("O", m.x, m.y, paint);

    if(x!=-1){
         Log.v("IP","LINE"+x+"   " + y+ "  "+ m.x+"    "+ m.y);
    canvas.drawLine(x, y,m.x, m.y, paint);
    }
    x=m.x;
    y=m.y;
}
x=y=-1;

}

}

Community
  • 1
  • 1
  • Hey take a look at the following SO question of mine.. this will help you. http://stackoverflow.com/questions/7524843/get-canvas-coordinates-after-scaling-up-down-or-dragging-in-android – Awais Tariq Oct 17 '12 at 07:19

3 Answers3

1

Please try this code

public boolean onTouchEvent(MotionEvent env) {
float x = env.getX() / mScaleFactor + rect.left;
float y = env.getY() / mScaleFactor + rect.top;
}
1

Use this code

public boolean onTouchEvent(MotionEvent env) {
float x = env.getX() / mScaleFactor + rect.left;
float y = env.getY() / mScaleFactor + rect.top;
}
vinmnit48
  • 26
  • 2
0

you can get 9 point array from the matrix which contain the relative x,y and scale factor in x and y use this to convert you current x,y (which is with respect to screen) to x,y on original image and reconvert it before drawing again on different zoom levels.

Mehul Mistri
  • 15,037
  • 14
  • 70
  • 94
vinmnit48
  • 26
  • 2