Code example for ExifInterface

Methods: getAttributeInt, saveAttributes, setAttribute

0
			return false; 
		} 
		// can only rotate jpeg via EXIF - must manually rotate other types of image 
		if (imagePath.endsWith(".jpg") || imagePath.endsWith(".jpeg")) {
			try { 
				ExifInterface exif = new ExifInterface(imagePath);
				int exifRotation = exif
						.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
				int newRotation = ExifInterface.ORIENTATION_UNDEFINED;
				switch (exifRotation) {
					case ExifInterface.ORIENTATION_UNDEFINED: // usually means that the current rotation is normal
					case ExifInterface.ORIENTATION_NORMAL:
						newRotation = (antiClockwise ? ExifInterface.ORIENTATION_ROTATE_270
								: ExifInterface.ORIENTATION_ROTATE_90);
						break; 
					case ExifInterface.ORIENTATION_ROTATE_90:
						newRotation = (antiClockwise ? ExifInterface.ORIENTATION_NORMAL
								: ExifInterface.ORIENTATION_ROTATE_180);
						break; 
					case ExifInterface.ORIENTATION_ROTATE_180:
						newRotation = (antiClockwise ? ExifInterface.ORIENTATION_ROTATE_90
								: ExifInterface.ORIENTATION_ROTATE_270);
						break; 
					case ExifInterface.ORIENTATION_ROTATE_270:
						newRotation = (antiClockwise ? ExifInterface.ORIENTATION_ROTATE_180
								: ExifInterface.ORIENTATION_NORMAL);
						break; 
				} 
				exif.setAttribute(ExifInterface.TAG_ORIENTATION, Integer.toString(newRotation));
				exif.saveAttributes();
				return true; 
			} catch (IOException e) {
				return false; // couldn't read the file, or failed to set the exif attributes 
			}