0

如何将 android.graphics.Picture 旋转 90 度?

*注意:不,它不是位图形式

4

1 回答 1

1

如果您要覆盖onDraw(),那么您可以执行以下操作:

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

如果您只想旋转图像本身,则可以使用此方法:

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;
}
于 2013-01-08T22:09:34.513 回答