List of usage examples for android.media ExifInterface TAG_ORIENTATION
String TAG_ORIENTATION
To view the source code for android.media ExifInterface TAG_ORIENTATION.
Click Source Link
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 w w . j av a 2s . com*/ * 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
private static int getOrientationFromExif(Uri imageUri, Context context) { int orientation = -1; Log.i("Photo Editor", "imageUri = " + imageUri); // File imageFile = new File(getRealPathFromUri(imageUri, context)); File imageFile = new File(imageUri.getPath()); try {/*from w ww .j a va 2 s.c om*/ ExifInterface exif; Log.i("Photo Editor", "imageFile.getAbsolutePath() = " + imageFile.getAbsolutePath()); exif = new ExifInterface(imageFile.getAbsolutePath()); orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); } catch (IOException e) { e.printStackTrace(); } return orientation; }
From source file:Main.java
/** * Get the orientation rotate degree of an image file. * /*from ww w . j a va2 s . c o m*/ * @param soureFilePath * The file path of the image. * @return The orientation rotate degree of an image file(90 or 180 or 270). <br> * 0, if the image file has no orientation rotate degree or the * source file is not a valid image file. */ public static int getOrientationRotateDegree(String soureFilePath) { if (null == soureFilePath) { return 0; } try { ExifInterface exif = new ExifInterface(soureFilePath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: { return 90; } case ExifInterface.ORIENTATION_ROTATE_180: { return 180; } case ExifInterface.ORIENTATION_ROTATE_270: { return 270; } default: { return 0; } } } catch (IOException e) { e.printStackTrace(); return 0; } }
From source file:Main.java
public static int getDegress(String path) { int degree = 0; try {// w w w . ja v a 2 s.c om 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
private static Bitmap turnPic(final String path, Bitmap bitmap) { ExifInterface exif;// w w w . j a v a 2 s . co m final int ninetyDegrees = 90; int rotationAngle = 0; Matrix matrix = new Matrix(); if (path != null) { try { exif = new ExifInterface(path); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotationAngle = ninetyDegrees; break; case ExifInterface.ORIENTATION_ROTATE_180: rotationAngle = ninetyDegrees * 2; break; case ExifInterface.ORIENTATION_ROTATE_270: rotationAngle = ninetyDegrees * 3; break; case ExifInterface.ORIENTATION_NORMAL: default: break; } } catch (IOException e) { e.printStackTrace(); return bitmap; } if (rotationAngle != 0) { matrix.postRotate(rotationAngle); } bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } return bitmap; }
From source file:Main.java
public static int getRotateDegree(String path) { int result = 0; try {//from w w w . java 2s . c o m ExifInterface exif = new ExifInterface(path); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: result = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: result = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: result = 270; break; } } catch (IOException ignore) { return 0; } return result; }
From source file:Main.java
public static int readPictureDegree(String path) { int degree = 0; try {//from ww w .j a va 2 s. com ExifInterface exifInterface = new ExifInterface(path); int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); 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; case ExifInterface.ORIENTATION_NORMAL: degree = 0; break; case ExifInterface.ORIENTATION_UNDEFINED: degree = 0; break; case -1: degree = 0; break; } } catch (IOException e) { e.printStackTrace(); } return degree; }
From source file:Main.java
public static int getOrientation(final String imagePath) { int rotate = 0; try {//from www .j a v a2s . co m 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
private static int getRotationFromCamera(Context context, Uri imageFile) { int rotate = 0; try {/*from w ww. j a va 2 s . c o m*/ context.getContentResolver().notifyChange(imageFile, null); ExifInterface exif = new ExifInterface(imageFile.getPath()); 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 getOrientation(Context context, Uri photoUri, File file) { /* it's on the external media. */ Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor != null && cursor.getCount() != 1) { cursor.moveToFirst();//from w w w .jav a 2 s. c om return cursor.getInt(0); } int rotate = 0; ExifInterface exif = null; try { exif = new ExifInterface(file == null ? getPath(context, photoUri) : file.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } 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; case ExifInterface.ORIENTATION_NORMAL: rotate = 0; break; } return rotate; }