List of usage examples for android.media ExifInterface getAttributeInt
public int getAttributeInt(String tag, int defaultValue)
From source file:Main.java
public static int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath) { int rotate = 0; try {//from w ww . j a v a 2 s . c o m context.getContentResolver().notifyChange(imageUri, null); File imageFile = new File(imagePath); ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; } } catch (Exception e) { e.printStackTrace(); } return rotate; }
From source file:Main.java
public static int readPictureDegree(String path) { int degree = 0; try {//from w w w . j ava2 s .co m ExifInterface exifInterface = new ExifInterface(path); int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; break; } } catch (IOException e) { e.printStackTrace(); } return degree; }
From source file:Main.java
/** * Adjust the photo orientation// w w w . j av a 2 s. c o m * @param pathToFile * @return */ public static Bitmap adjustPhotoOrientation(String pathToFile) { try { Bitmap bitmap = BitmapFactory.decodeFile(pathToFile); ExifInterface exif = new ExifInterface(pathToFile); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int rotate = 0; switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; } if (rotate != 0) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); // Setting pre rotate Matrix mtx = new Matrix(); mtx.preRotate(rotate); // Rotating Bitmap & convert to ARGB_8888, required by tess bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false); bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); return bitmap; } } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static int defineExifOrientation(Uri imageUri, String mimeType) { int rotation = 0; if ("image/jpeg".equalsIgnoreCase(mimeType) && "file".equals(imageUri.getScheme())) { try {/*from w ww. j a va 2 s. com*/ ExifInterface exif = new ExifInterface(imageUri.getPath()); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); Log.e("dsd", "exifOrientation:" + exifOrientation); switch (exifOrientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: case ExifInterface.ORIENTATION_NORMAL: rotation = 0; break; case ExifInterface.ORIENTATION_TRANSVERSE: case ExifInterface.ORIENTATION_ROTATE_90: rotation = 90; break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: case ExifInterface.ORIENTATION_ROTATE_180: rotation = 180; break; case ExifInterface.ORIENTATION_TRANSPOSE: case ExifInterface.ORIENTATION_ROTATE_270: rotation = 270; break; } } catch (IOException e) { Log.e("dsd", "Can't read EXIF tags from file [%s]" + imageUri); } } return rotation; }
From source file:Main.java
public static int getImageDegrees(String pathName) { int degrees = 0; try {//ww w. j a va2s . c om ExifInterface exifInterface = new ExifInterface(pathName); int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: degrees = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degrees = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degrees = 270; break; } } catch (Exception e) { e.printStackTrace(); } return degrees; }
From source file:Main.java
private static int getPhotoRotationDegree(String imagePath) { int rotate = 0; try {/*from w w w .j a va 2s .co m*/ File imageFile = new File(imagePath); ExifInterface exifDataReader = new ExifInterface(imageFile.getAbsolutePath()); int orientation = exifDataReader.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; } } catch (IOException e) { Log.e("CATROID", "Could not find file to initialize ExifInterface.", e); } return rotate; }
From source file:Main.java
/** * Checks if the orientation of the image is correct, if it's not it will rotate the image * * @param pBitmap/*w ww . ja v a 2s . co m*/ * The bitmap to check the orientation for * @param pPath * The path to the image, used to load the exif interface * @return Bitmap in the correct orientation */ public static Bitmap imageOreintationValidator(Bitmap pBitmap, String pPath) { ExifInterface ei; try { ei = new ExifInterface(pPath); int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: pBitmap = rotateImage(pBitmap, 90); break; case ExifInterface.ORIENTATION_ROTATE_180: pBitmap = rotateImage(pBitmap, 180); break; case ExifInterface.ORIENTATION_ROTATE_270: pBitmap = rotateImage(pBitmap, 270); break; } } catch (IOException e) { e.printStackTrace(); } return pBitmap; }
From source file:Main.java
public static Matrix getRotationMatrixForImage(Context ctx, Uri contentUri) { String pathToImage = getAbsolutePathFromUri(ctx, contentUri); ExifInterface exif; try {//from w w w . j a v a 2 s .co m exif = new ExifInterface(pathToImage); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); Matrix matrix = new Matrix(); if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { matrix.postRotate(90); } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { matrix.postRotate(180); } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { matrix.postRotate(270); } return matrix; } catch (IOException e) { return new Matrix(); } }
From source file:Main.java
public static Bitmap createCorrectlyRotatedBitmapIfNeeded(Bitmap bitmap, String jpegPath, float scale) { // Rotate the image if necessary; all images are shot in LANDSCAPE mode try {/*from www .jav a2 s. c om*/ ExifInterface exif = new ExifInterface(jpegPath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); Log.d("CashLensUtils", "image has orientation " + Integer.toString(orientation) + ", width " + Integer.toString(bitmap.getWidth()) + ", height " + Integer.toString(bitmap.getHeight())); Matrix matrix = new Matrix(); if (scale != 1.0f) matrix.preScale(scale, scale); // From http://sylvana.net/jpegcrop/exif_orientation.html // For convenience, here is what the letter F would look like if it were tagged correctly // and displayed by a program that ignores the orientation tag (thus showing the stored image): // (1) 2 (3) 4 5 (6) 7 (8) // // 888888 888888 88 88 8888888888 88 88 8888888888 // 88 88 88 88 88 88 88 88 88 88 88 88 // 8888 8888 8888 8888 88 8888888888 8888888888 88 // 88 88 88 88 // 88 88 888888 888888 if (orientation == 3) matrix.postRotate(180); else if (orientation == 6) matrix.postRotate(90); else if (orientation == 8) matrix.postRotate(-90); if (orientation != 1 || scale != 1.0f) { // Create a new image with the correct (maybe rotated) width/height Bitmap newImage = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); Log.d("CashLensUtils", "created a new image with width " + Integer.toString(newImage.getWidth()) + ", height " + Integer.toString(newImage.getHeight())); // Replace original image return newImage; } } catch (IOException e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static int getExifRotation(File imageFile) { if (imageFile == null) return 0; try {/*w ww.j a v a 2s . c o m*/ ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath()); // We only recognize a subset of orientation tag values switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) { case ExifInterface.ORIENTATION_ROTATE_90: return 90; case ExifInterface.ORIENTATION_ROTATE_180: return 180; case ExifInterface.ORIENTATION_ROTATE_270: return 270; default: return ExifInterface.ORIENTATION_UNDEFINED; } } catch (IOException e) { return 0; } }