0

How to rotate android.graphics.Picture 90 degrees?

*Note: No its not in Bitmap form

TN888
  • 7,659
  • 9
  • 48
  • 84
MobileMon
  • 8,341
  • 5
  • 56
  • 75

1 Answers1

1

If you are overriding onDraw() then you can do the following:

canvas.save();
canvas.rotate(90f, picture.getWidth()/2, picture.getHeight/2);
canvas.drawPicture(picture);
canvas.restore();

If you only want to rotate the image itself then you could use this method:

public Picture rotatePicture(float degrees, Picture picture) {
    int width = picture.getWidth();
    int height = picture.getHeight();

    Picture rotatedPicture = new Picture();
    Canvas canvas = rotatedPicture.beginRecording(width, height);
    canvas.save();
    canvas.rotate(degrees, width/2, height/2);
    picture.draw(canvas);
    canvas.restore();
    rotatedPicture.endRecording();

    return rotatedPicture;
}
danjohnson
  • 80
  • 8
  • I actually do this but it depends what you're trying to accomplish. c.drawPicture(picture, r); c.save(); c.rotate(90f, picture.getWidth()/2, picture.getHeight()/2); c.restore(); – MobileMon Feb 25 '13 at 15:10