Exif { public void rotate(int degrees) { if (degrees % 90 != 0) { Log.w(TAG, String.format("Can only rotate in right angles (eg. 0, 90, 180, 270). %d is unsupported.", degrees)); mExifInterface.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_UNDEFINED)); return; } degrees %= 360; int orientation = getOrientation(); while (degrees < 0) { degrees += 90; switch (orientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: orientation = ExifInterface.ORIENTATION_TRANSPOSE; break; case ExifInterface.ORIENTATION_ROTATE_180: orientation = ExifInterface.ORIENTATION_ROTATE_90; break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: orientation = ExifInterface.ORIENTATION_TRANSVERSE; break; case ExifInterface.ORIENTATION_TRANSPOSE: orientation = ExifInterface.ORIENTATION_FLIP_VERTICAL; break; case ExifInterface.ORIENTATION_ROTATE_90: orientation = ExifInterface.ORIENTATION_NORMAL; break; case ExifInterface.ORIENTATION_TRANSVERSE: orientation = ExifInterface.ORIENTATION_FLIP_HORIZONTAL; break; case ExifInterface.ORIENTATION_ROTATE_270: orientation = ExifInterface.ORIENTATION_ROTATE_90; break; case ExifInterface.ORIENTATION_NORMAL: case ExifInterface.ORIENTATION_UNDEFINED: default: orientation = ExifInterface.ORIENTATION_ROTATE_270; break; } } while (degrees > 0) { degrees -= 90; switch (orientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: orientation = ExifInterface.ORIENTATION_TRANSVERSE; break; case ExifInterface.ORIENTATION_ROTATE_180: orientation = ExifInterface.ORIENTATION_ROTATE_270; break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: orientation = ExifInterface.ORIENTATION_TRANSPOSE; break; case ExifInterface.ORIENTATION_TRANSPOSE: orientation = ExifInterface.ORIENTATION_FLIP_HORIZONTAL; break; case ExifInterface.ORIENTATION_ROTATE_90: orientation = ExifInterface.ORIENTATION_ROTATE_180; break; case ExifInterface.ORIENTATION_TRANSVERSE: orientation = ExifInterface.ORIENTATION_FLIP_VERTICAL; break; case ExifInterface.ORIENTATION_ROTATE_270: orientation = ExifInterface.ORIENTATION_NORMAL; break; case ExifInterface.ORIENTATION_NORMAL: case ExifInterface.ORIENTATION_UNDEFINED: default: orientation = ExifInterface.ORIENTATION_ROTATE_90; break; } } mExifInterface.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(orientation)); } Exif(File file);  Exif(String filePath);  Exif(InputStream is); private  Exif(ExifInterface exifInterface); void save(); @Override String toString(); int getWidth(); int getHeight(); @Nullable String getDescription(); void setDescription(@Nullable String description); int getRotation(); boolean isFlippedVertically(); boolean isFlippedHorizontally(); long getLastModifiedTimestamp(); long getTimestamp(); @Nullable Location getLocation(); void rotate(int degrees); void flipVertically(); void flipHorizontally(); void attachTimestamp(); void removeTimestamp(); void attachLocation(Location location); void removeLocation();  }
@Test public void rotate() { assertEquals(0, exif.getRotation()); exif.rotate(90); assertEquals(90, exif.getRotation()); exif.rotate(90); assertEquals(180, exif.getRotation()); exif.rotate(90); assertEquals(270, exif.getRotation()); exif.rotate(90); assertEquals(0, exif.getRotation()); exif.rotate(-90); assertEquals(270, exif.getRotation()); exif.rotate(360); assertEquals(270, exif.getRotation()); exif.rotate(500 * 360 - 90); assertEquals(180, exif.getRotation()); }