java - Wrong Y coordinate from TextView on Bitmap using Canvas.drawText -


please me problem or @ least give me advice. have imageview overlayed textview. user can drag text position on image. after, want save image text @ chosen position.

layout (textview add dynamically root element):

<linearlayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center_horizontal|center_vertical"> <framelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/root" android:padding="0dp" android:layout_margin="0dp"> <imageview     android:id="@+id/image"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="center_horizontal"     android:adjustviewbounds="true"     android:scaletype="centerinside"/> </framelayout> </linearlayout> 

all problem in y coordinate wrong. i'm try 2 function find x , y coordinates.

first:

public float[] getposition(imageview imageview, textview textview) { matrix matrix = new matrix(); imageview.getimagematrix().invert(matrix); float[] coord = {textview.getx(), textview.gety()}; matrix.mappoints(coord);  return coord; } 

and better one, using function give accurate x.

private float[] getcoordinates(imageview iv, bitmap bm, float x, float y){     float projectedx = (float) ((double)x * ((double)bm.getwidth()/(double)iv.getwidth()));     float projectedy = (float) ((double)y * ((double)bm.getheight()/(double)iv.getheight()));      return new float[]{projectedx, projectedy}; } 

any advice? y higher desired position when canvas draw text.

here code save data canvas.drawtext:

bundle bundle = new bundle();                     textview textview = (textview)relativelayout.getchildat(i);                     bundle.putstring("text", ((textview) relativelayout.getchildat(i)).gettext().tostring());                     bundle.putfloatarray("coord", getposition(imageview,textview));                     bundle.putfloat("size", size*scale);                     new asyncdraw().execute(bundle); 

and after in asynctask:

     bundle bundle = bundles[0];         string text = bundle.getstring("text");         float[] coord = bundle.getfloatarray("coord");         canvas canvas = new canvas(oriented);         paint paint = new paint();         paint.setantialias(true);         paint.settextsize(bundle.getfloat("size"));         canvas.drawtext(text, coord[0],coord[1],paint); 

try mapping height values device screen metrics using typedvalue.applydimension method


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -