android - rotate image by 360 degrees using ontouch -
i want rotate image 360 degrees using ontouch. code had used maximum rotation getting 120 degrees. code had used
this code in ontouch event
case motionevent.action_move: newrot = rotation(event); float r = newrot - d; matrix.postrotate(r, view.getmeasuredwidth()/ 2, view.getmeasuredheight()/ 2);
and rotation method
private float rotation(motionevent event) { double delta_x = (event.getx(0) - event.getx(1)); double delta_y = (event.gety(0) - event.gety(1)); double radians = math.atan2(delta_y, delta_x); log.v("", "=================xxxxxxxxxxxvvvxx==============" + math.todegrees(radians)); return (float) math.todegrees(radians); }
with code getting 120 degrees rotation on both clockwisw , anti-clockwise. please suggest me, did need change in code or working code.
this method might works me.
public static bitmap rotate(bitmap b, int degrees) { if (degrees != 0 && b != null) { matrix m = new matrix(); m.setrotate(degrees, (float) b.getwidth() / 2, (float) b.getheight() / 2); try { bitmap b2 = bitmap.createbitmap(b, 0, 0, b.getwidth(), b.getheight(), m, true); if (b != b2) { b.recycle(); b = b2; } } catch (outofmemoryerror ex) { throw ex; } } return b; }
Comments
Post a Comment