Find new coordinates of overlay object on the canvas after modifying on matrix in Android -
i'm working on android project , i'm using view class drawing image , overlays. i'm using code drawing image , circle (it working fine):
@override protected void ondraw(canvas canvas) { super.ondraw(canvas); if (!isinitialized) { w = getwidth(); h = getheight(); position.set(w / 2, h / 2); // scaling image fit screen if(width<=height) { scale=((float)w)/width; } else { scale=((float)h)/height; } isinitialized = true; } paint paint = new paint(); matrix.reset(); matrix.posttranslate(-width / 2.0f, -height / 2.0f); matrix.postrotate((float)(angle*180/math.pi)); matrix.postscale(scale, scale); matrix.posttranslate(position.getx(), position.gety()); canvas.drawbitmap(bitmap, matrix, paint); canvas.concat(matrix); canvas.drawcircle(testpoint.x, testpoint.y, 20, paint ); } now want show popupwindow windows tip on image , on same position of circle (testpoint). popupwindows not drawable object, how can find new coordinates of testpoint after scaling, rotation , translating put coordinates of popupwindow same.
i'm trying write code , working fine, rotation , translating without scaling, code wrote:
int offsetx=(int) (-(width / 2.0f)+position.getx())+rc.left; int offsety=(int) (-(height / 2.0f)+position.gety())+rc.top; point rotatedpoint = rotatepoint(testpoint, centerpoint, angle); rotatedpoint.x +=offsetx; rotatedpoint.y +=offsety; popup.update(rotatedpoint.x, rotatedpoint.y, -1, -1); where rc offset difference between bitmap view coordinates , screen coordinates.
and i'm tested rotatepoint function , working correctly.
note: when scale equal 1 (disable scaling) position of popup window updating correctly if rotate or move image.
how can merged scale (if not equal 1 only) equations?
or there way find new coordinates of overlay object on canvas after modifying on matrix?
please me solved problem. grateful help. thank you.
try use matrix.mappoints()
u must have absolute coordinates of image
how absolute coord?
void calculacoordenadasimagen(motionevent e){ float []m = new float[9]; matrix.getvalues(m); float transx = m[matrix.mtrans_x] * -1; float transy = m[matrix.mtrans_y] * -1; float scalex = m[matrix.mscale_x]; float scaley = m[matrix.mscale_y]; lasttouchx = (int) ((e.getx() + transx) / scalex); lasttouchy = (int) ((e.gety() + transy) / scaley); lasttouchx = math.abs(lasttouchx); lasttouchy = math.abs(lasttouchy); } then use 2 different arrays save points
int [] absolute = new int[2]; absolute[0]=lasttouchx; absolute[1]=lasttouchy; int [] points = new int[2]; points = matrix.mappoints(absolute) in absolute u have absolute coordinates , in points u have points u want know
i wish help!
Comments
Post a Comment