Image Processing – Rotate Image On The Fly
Image rotation is quite simple over Android. The trick here is to make use of Matrix.
From my original beauty:
These are several image rotation on degrees:
Pretty nice effect!
Here the implemetation:
public static Bitmap rotate(Bitmap src, float degree) { // create new matrix Matrix matrix = new Matrix(); // setup rotation degree matrix.postRotate(degree); // return new bitmap rotated using matrix return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); }
Hope you like it!
Cheers,
Pete Houston
Categories: Tutorials
image, processing, rotate, tutorials
I applied it properly, but the image is not rotating.
how we can this type of method call in a button ??
This is the most memory inefficient way to do so.
What you do is run a postRotate() on an existing matrix, and when drawing that bitmap on a canvas, apply this matrix.
Creating a new bitmap for this sort of thing is pointless and inefficient.
More information here: http://judepereira.com/blog/multi-touch-in-android-translate-scale-and-rotate/
Thanks for your post, i have a problem that bitmap is rotating fine but bitmap size is chaged for every rotation….
That’s a big problem, you will get OutOfMemoryError soon. See this: http://stackoverflow.com/questions/12159852/why-this-image-switching-code-has-memory-leak
Nice post ..
Cool