Scale canvas and center

I want to scale the canvas with a bitmap drawn on it. I can scale the canvas, but the bitmap drawn on it moves to the upper left, respectively, lower right.

@Override protected void onDraw(Canvas canvas) { canvas.translate(mPosX, mPosY); canvas.scale(mScaleFactor, mScaleFactor); //draw bitmap } 

Over the past few days, I have tried many different approaches from manipulating translation coordinates to turning points for scaling. But for me nothing happened. I am sure there should be an easy solution for my problem.

Thanks in advance

+7
source share
1 answer

As you mentioned, the pivot point is the right way to do this:

 canvas.scale(2,2, redCircle.x, redCircle.y); 

will work. No need for additional translation.

+13
source

All Articles