Created
March 7, 2011 17:25
-
-
Save codeswimmer/858833 to your computer and use it in GitHub Desktop.
Android: rotate a bitmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Bitmap rotateBitmap(Bitmap original, float degrees) { | |
int width = original.getWidth(); | |
int height = original.getHeight(); | |
Matrix matrix = new Matrix(); | |
matrix.preRotate(degrees); | |
Bitmap rotatedBitmap = Bitmap.createBitmap(original, 0, 0, width, height, matrix, true); | |
Canvas canvas = new Canvas(rotatedBitmap); | |
canvas.drawBitmap(original, 5.0f, 0.0f, null); | |
return rotatedBitmap; | |
} |
great !
To understand, this piece of code will rotate my photo to the right position or I choose how much and where it will rotate. Thank you.
Thank you, nice code !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bitmap.createBitmap
is java call and might be null. And I think we can useNumber
for parameter andinfix
for readabilityUsage
bitmap rotate 90