Reputation: 134
I have a trouble with scaling bitmap and then draw on it in Android. From the beginning, I have a custom view, with onDraw method, I'm drawing something on it's canvas. Now, I want to scale that drawing smoothly (still on canvas) and then draw something on that canvas, without clearing it (over that scaled drawing). How to accomplish this?
I have tried scaling whole view with build-in animation mechanism. Scaling is smooth, but it is not the way, because it is scaling whole component, not only the drawing. Is there any way to scale drawing smoothly and then draw on it?
Thanks in advance.
Upvotes: 0
Views: 1047
Reputation: 57672
You could implement the scaling animation by yourself. You could call invalidate()
as long as you need to scale and measure the time between the onDraw()
calls and calculate the amount of scaling you need. The scaling itself would be simply done by a call to canvas.drawBitmap(bitmap, matrix, paint)
where your matrix must represent the scaling.
Another method would be to use ScaleAnimation where the Transformation contains a matrix you could use, too.
Drawing over the bitmap is simply done: just draw on the same canvas in onDraw()
after you have drawn the scaled image. As only the image scales, the new drawn stuff is not scaled.
A third solution might be a bit more complex. You could, instead of scaling the bitmap, just scale the canvas. Scale down the canvas, draw the bitmap on it and restore the canvas. After that you can draw the rest.
Upvotes: 1