Get Canvas coordinates after scaling up/down or dragging in android
Done it finally by myself.
Draw everything by applying this formula to (px,py) coordinates:
float px = ev.getX() / mScaleFactor + rect.left;float py = ev.getY() / mScaleFactor + rect.top;rect = canvas.getClipBounds();//Get them in on Draw function and apply above formula before drawing
@Overrideprotected void onDraw(Canvas canvas) { super.onDraw(canvas); clipBounds_canvas = canvas.getClipBounds(); /////Do whatever you want to do..!!! };@Overridepublic boolean onTouchEvent(MotionEvent ev) { int x = ev.getX() / zoomFactor + clipBounds_canvas.left; int y = ev.getY() / zoomFactor + clipBounds_canvas.top; //Use the above two values insted of ev.getX() and ev.getY();}
Hope this will help.