java - Android Activity MotionEvent coordinates to ImageView Canvas -


i'd catch coordinates of touch event via 'ontouchevent'. in activity have following code that:

public boolean ontouchevent(motionevent event) {     try {         if (event.getaction() == motionevent.action_down) {                 point p = new point();                 p.set((int) event.getrawx(), (int) event.getrawy());                                      // point added list here                      return true;         }          updatedraw();     }      catch (exception e) {         log.wtf("error", e.getmessage());     }      return false; } 

the activity's xml layout looks this:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"  tools:context=".marklinesactivity" >  <imageview     android:id="@+id/handview"     android:layout_width="wrap_content"     android:layout_height="fill_parent"     android:layout_alignparentleft="true"     android:layout_alignparenttop="true"     android:scaletype="fitxy" /> 

now in updatedraw() function actual problem occurs. because try catch 3 coordinates via 'ontouchevent' , draw them using 'path'. unfortunately points @ incorrect locations. inside updatedraw():

canvas tempcanvas = new canvas(currentbitmap);  tempcanvas.drawbitmap(origbitmap, 0, 0, null);  tempcanvas.drawpath(p, pa); 

this how create coordinates path:

p.moveto(points.get(currentlinestate).get(0).x,    points.get(currentlinestate).get(i).y);  (int = 1; < 3; i++) { try {     p.lineto( (points.get(currentlinestate).get(i).x),                       (points.get(currentlinestate).get(i).y) );         } catch (exception e) {         } } } 

note: points defined hashmap<string, arraylist<point>> , p being path instance.

the last part of updatedraw() drawing content created canvas on imageview:

((imageview) findviewbyid(r.id.handview)).setimagebitmap(currentbitmap); 

now question is: there wrong way of getting actual coordinates (i tried using event.getx() etc.) or maybe xml? tried extending class imageview myself , draw overriding 'ondraw' created incorrect positions points. thanks.

if want map between view , image coordinates use matrix getimagematrix() method.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -