0

I have a bitmap from camera , after resize , it change to horizontal , I need to rotate 90 degree , but most of the sample are use Matrix to rotate , but when I new Matrix , it said matrix is deprecated , than I try to use CANVAS , following this , first time to use it , trying to figure it out , but can not rotate it , app crash , help please

code

  resizePhoto = BitmapFactory.decodeFile(imageLocation,bmOption);

//  R o t a t e    B i t m a p   90 degree

    Canvas canvas = new Canvas(resizePhoto);
    canvas.rotate(90);
    canvas.drawBitmap(resizePhoto , null ,null);
Community
  • 1
  • 1
Awei Hsue
  • 257
  • 5
  • 19

2 Answers2

1
Matrix matrix = new Matrix();
matrix.setRotate(angle, imageCenterX, imageCenterY);
yourCanvas.drawBitmap(yourBitmap, matrix, null);
Hazonko
  • 1,025
  • 1
  • 15
  • 30
0

You might want to rotate using a matrix passed into Bitmap.createBitmap. It should be faster than using a Canvas.

Matrix matrix = new Matrix();
matrix.setRotate(angle);
Bitmap resizePhoto = BitmapFactory.decodeFile(imageLocation, bmOption);
Bitmap rotatedPhoto = Bitmap.createBitmap(resizePhoto, 0, 0, 
    resizePhoto.getWidth(), resizePhoto.getHeight(), matrix, true);
resizePhoto.recycle();

You might need to swap the getWidth() and getHeight() around for an exact 90 degree rotation. I forget.

Simon
  • 10,932
  • 50
  • 49