Scaling canvas and keeping center

android, canvas

Solution

Like you mentioned, the pivot point is the correct way to do this:

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

will work. There is no need for extra translation.

Problem

I'm want to scale a canvas with a bitmap drawn on it. I'm able to 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 } ``` For the last few days I tried many different approaches from manipulating translation coordinates to pivot points for scaling. But nothing did work for me. I'm pretty sure there must be an easy solution for my problem. Thanks in advance

Original source