Friday, 23 August 2013

Using an ImageView transform matrix instead of canvas.scale(float, float, float, float)

Using an ImageView transform matrix instead of canvas.scale(float, float, float, float) References I need to change the way I am scaling and moving my imageview to using a matrix instead of calling canvas.scale(,,,,), but I cannot figure out the proper calls to do this. I had this in my ScaleListener listener class\'s onScale method public boolean onScale(ScaleGestureDetector detector) { ...//determining zoom level and pivot points offset child.zoom(scaleFactor, zoomCenter[0], zoomCenter[1]); } I had in the child ImageView\'s onDraw method: protected void onDraw(Canvas canvas){ super.onDraw(canvas); canvas.scale(mScaleFactor, mScaleFactor, mPosX, mPosY); ... //do all the drawing here } public void zoom(float scaleFactor, float zoomCenterX, float zoomCenterY) { mScaleFactor = scaleFactor; mPosX = zoomCenterX; mPosY = zoomCenterY; //redraw and remeasure the mapview after zooming in invalidate(); } I would like something like this in the onScale method: public boolean onScale(ScaleGestureDetector detector) { ...//calculating scale and offsets Matrix m = child.getImageMatrix(); m.reset(); m.postScale(scaleFactor, scaleFactor); m.postTranslate(zoomCenter[0], zoomCenter[1]); child.setScaleType(ScaleType.MATRIX); child.setImageMatrix(m); child.invalidate(); return true; } But this does not appear to be doing anything...am I missing something here? I tried using child.getMatrix() instead but that through an IllegalStateException saying the matrix cannot be modified. Any help would be great!

No comments:

Post a Comment