List of usage examples for android.media ExifInterface ORIENTATION_NORMAL
int ORIENTATION_NORMAL
To view the source code for android.media ExifInterface ORIENTATION_NORMAL.
Click Source Link
From source file:Main.java
public static Bitmap rotateBitmapInNeeded(String path, Bitmap srcBitmap) { if (TextUtils.isEmpty(path) || srcBitmap == null) { return null; }//from w ww .j a va 2 s . c o m ExifInterface localExifInterface; try { localExifInterface = new ExifInterface(path); int rotateInt = localExifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); float rotate = getImageRotate(rotateInt); if (rotate != 0) { Matrix matrix = new Matrix(); matrix.postRotate(rotate); Bitmap dstBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight(), matrix, false); if (dstBitmap == null) { return srcBitmap; } else { if (srcBitmap != null && !srcBitmap.isRecycled()) { srcBitmap.recycle(); } return dstBitmap; } } else { return srcBitmap; } } catch (IOException e) { e.printStackTrace(); return srcBitmap; } }
From source file:Main.java
public static int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath) { int rotate = 0; try {// ww w. ja va 2 s .com 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 Matrix rotateImage(Context context, Uri imageUri, File f) { Matrix matrix = new Matrix(); try {/* w w w .j ava2s .c om*/ if (imageUri != null) { context.getContentResolver().notifyChange(imageUri, null); } ExifInterface exif = new ExifInterface(f.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: matrix.postRotate(270); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.postRotate(180); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.postRotate(90); break; } } catch (Exception e) { e.printStackTrace(); } return matrix; }
From source file:Main.java
/** * This method resets bitmap orientation to 0 if not. * /*from www . jav a 2s . com*/ * @param path * @param bitmap * @return bitmap with 0 degree orientation */ public static Bitmap resetBitmapOrientation(String path, Bitmap bitmap) { // TODO Auto-generated method stub int rotate = 0; try { ExifInterface ei = new ExifInterface(path); int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; default: // do nothing... break; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (rotate == 0) { return bitmap; } else { Matrix m = new Matrix(); m.postRotate(rotate); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); } }
From source file:Main.java
static public Bitmap getOrientedBitmapFromBitmapAndPath(Bitmap bitmap, String filePath) { Log.d(TAG, "[AirImagePickerUtils] Entering getOrientedBitmapFromBitmapAndPath"); try {/*from w ww . j a v a2 s . c o m*/ // Get orientation from EXIF ExifInterface exif = new ExifInterface(filePath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); // Compute rotation matrix Matrix rotation = new Matrix(); switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotation.preRotate(90); break; case ExifInterface.ORIENTATION_ROTATE_180: rotation.preRotate(180); break; case ExifInterface.ORIENTATION_ROTATE_270: rotation.preRotate(270); break; } // Return new bitmap Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath"); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), rotation, true); } catch (Exception exception) { Log.d(TAG, "Couldn't fix bitmap orientation: " + exception.getMessage()); Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath"); return bitmap; } }
From source file:Main.java
/** * Adjust the photo orientation//from www.j a v a 2s . com * @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 getRotationFromExif(Context context, String bitmapPath) { try {/* ww w . j av a 2 s. c o m*/ ExifInterface ei = new ExifInterface(bitmapPath); int exifOrientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: return 90; case ExifInterface.ORIENTATION_ROTATE_180: return 180; case ExifInterface.ORIENTATION_ROTATE_270: return 270; case ExifInterface.ORIENTATION_NORMAL: return 0; } } catch (Exception e) { } return -1; }
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//from w w w .j av a 2 s. 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 www .j a v a 2 s . c o m 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. * // w w w . j a v a 2s. 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; } }