Reputation: 24857
I am trying to rotate a bitmap when drawing it to a canvas. The problem is that when I call canvas.rotate(90) anything that is drawn after that does not actually get drawn. Running the following code will draw nothing to the screen when I have the rotate call in there. If I take out the rotate call it shows up fine. Why would the rotate call stop the bitmap from showing up on the canvas?
canvas.save();
canvas.rotate(90);
canvas.drawBitmap(leaves, null, leafRect, bitmapPaint);
canvas.restore();
Upvotes: 0
Views: 2449
Reputation: 44078
By default, rotate() will rotate the canvas from the exact center. You probably want to rotate from the center of your bitmap.
canvas.save();
canvas.rotate(90, leafRect.x + (leafRect.width / 2), leafRect.y + (leafRect.height / 2));
canvas.drawBitmap(leaves, null, leafRect, bitmapPaint);
canvas.restore();
More info at the docs rotate(angle, x, y)
Upvotes: 2