In many image related Android applications, we may need to rotate the bitmap(not ImageView). Here I added the code below to rotate the image at any possible angle using Matrix.

Bitmap bInput/*your input bitmap*/, bOutput; float degrees = 45;//rotation degree Matrix matrix = new Matrix(); matrix.setRotate(degrees); bOutput = Bitmap.createBitmap(bInput, 0, 0, bInput.getWidth(), bInput.getHeight(), matrix, true);
Thank you very much for your code. So simple, clean and works! I was reading some similar code in SO, but they were all so confusing.
You’re welcome 🙂
” Cannot resolve symbol ‘bOutput’ ”
how can i fix it ?
Please make sure you have the following line in your code.
Bitmap bInput/*your input bitmap*/, bOutput;
It defines the ‘bOutput’ variable.
When rotated by 45deg, the image shrinks to fit the bitmap. Is there a way that the image can be rotated but remain the same size? Even if it means portions of the image get cropped out?
For that, you need to calculate new height and width for that according to the angle I guess.
Were do i need to put this code?
You can use this where you want to rotate the image in the code.