Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Bitmap getRotateBitmap(File imageFile) throws IOException {
- InputStream inputStream = new FileInputStream(imageFile);
- Bitmap bmpSource = BitmapFactory.decodeStream(inputStream);
- inputStream.close();
- ExifInterface ei = new ExifInterface(imageFile.getCanonicalPath());
- int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
- float angle = 0;
- switch (orientation) {
- case ExifInterface.ORIENTATION_ROTATE_90:
- angle = 90;
- break;
- case ExifInterface.ORIENTATION_ROTATE_180:
- angle = 180;
- break;
- case ExifInterface.ORIENTATION_ROTATE_270:
- angle = 270;
- break;
- // etc.
- }
- Bitmap bmpRotate;
- if (angle == 0) {// do not change bitmap
- bmpRotate = bmpSource;
- } else {
- bmpRotate = rotateImage(bmpSource, angle);
- bmpSource.recycle();// free memory
- }
- return bmpRotate;
- }
- public static Bitmap rotateImage(Bitmap source, float angle) {
- Bitmap retVal;
- Matrix matrix = new Matrix();
- matrix.postRotate(angle);
- retVal = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
- return retVal;
- }
Advertisement
Add Comment
Please, Sign In to add comment