Home » Android » java – Resize a path in android canvas

java – Resize a path in android canvas

Posted by: admin June 15, 2020 Leave a comment


I have drawn an path in my canvas. On Single tap I want to resize the path. Say I want to make it double the original size.

I have tried path.transform but it shifts the path to a different location in canvass. This is the code I used for that

Matrix translateMatrix = new Matrix();

How can I resize a path in android?

How to&Answers:

I have tried the solution provided by smitalm. Still the path was shifting its location. I have tried this way and it worked for me.

Matrix scaleMatrix = new Matrix();
RectF rectF = new RectF();
path.computeBounds(rectF, true);
scaleMatrix.setScale(1.25f, 1.25f,rectF.centerX(),rectF.centerY());


Havent done this by myself, but you should probably use

Matrix scaleMatrix = new Matrix();
scaleMatrix.setScale(sx,sy, px, py);

where sx,sy should be 2,2 in your case, if you want double size
and px,py should probably be 0.5,0.5 in your case