Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public static Bitmap modifyOrientation(Bitmap bitmap, String image_absolute_path) throws IOException {
  2. ExifInterface ei = new ExifInterface(image_absolute_path);
  3. int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
  4.  
  5. switch (orientation) {
  6. case ExifInterface.ORIENTATION_ROTATE_90:
  7. return rotate(bitmap, 90);
  8.  
  9. case ExifInterface.ORIENTATION_ROTATE_180:
  10. return rotate(bitmap, 180);
  11.  
  12. case ExifInterface.ORIENTATION_ROTATE_270:
  13. return rotate(bitmap, 270);
  14.  
  15. case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
  16. return flip(bitmap, true, false);
  17.  
  18. case ExifInterface.ORIENTATION_FLIP_VERTICAL:
  19. return flip(bitmap, false, true);
  20.  
  21. default:
  22. return bitmap;
  23. }
  24. }
  25.  
  26. public static Bitmap rotate(Bitmap bitmap, float degrees) {
  27. Matrix matrix = new Matrix();
  28. matrix.postRotate(degrees);
  29. return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
  30. }
  31.  
  32. public static Bitmap flip(Bitmap bitmap, boolean horizontal, boolean vertical) {
  33. Matrix matrix = new Matrix();
  34. matrix.preScale(horizontal ? -1 : 1, vertical ? -1 : 1);
  35. return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement