List of usage examples for android.media ExifInterface ExifInterface
public ExifInterface(InputStream inputStream) throws IOException
From source file:Main.java
public static Bitmap processToteImage(String image_path, Bitmap bm) { Bitmap bitmap = null;/*from w w w . j av a 2 s . c om*/ try { ExifInterface exif = new ExifInterface(image_path); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); Log.d("EXIF", "Exif: " + orientation); Matrix matrix = new Matrix(); if (orientation == 6) { matrix.postRotate(90); } else if (orientation == 3) { matrix.postRotate(180); } else if (orientation == 8) { matrix.postRotate(270); } bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); // rotating // bitmap } catch (Exception e) { } return bitmap; }
From source file:Main.java
public static int getRotationAngle(String photoPath) { ExifInterface ei = null;//from w w w. j ava2s. c om try { ei = new ExifInterface(photoPath); } catch (IOException e) { Log.e(TAG, "Unexpected error occurred when getting rotation angle."); } int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: Log.d(TAG, "90 Degrees rotation needed"); return 90; case ExifInterface.ORIENTATION_ROTATE_180: Log.d(TAG, "180 Degrees rotation needed"); return 180; case ExifInterface.ORIENTATION_ROTATE_270: Log.d(TAG, "270 Degrees rotation needed"); return 270; case ExifInterface.ORIENTATION_NORMAL: default: Log.d(TAG, "0 Degrees rotation needed"); return 0; } }
From source file:Main.java
/** * Get Image Orientation from file/*from w w w. j a v a 2 s . c o m*/ * * @param imageFile File for which orientation is changed * @return Current Orientation */ public static int getBitmapOrientation(File imageFile) { try { ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath()); return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); } catch (IOException e) { } return 0; }
From source file:Main.java
public static int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath) { int rotate = 0; try {//from w w w . j a 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
/** * Extracts the EXIF rotation tag of an image file. * * @param filePath Path to the image file * @return Rotation in degrees/*from w w w. j a v a 2 s . co m*/ * @throws IOException */ public static int getExifRotation(String filePath) throws IOException { ExifInterface exif = new ExifInterface(filePath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: return 90; case ExifInterface.ORIENTATION_ROTATE_180: return 180; case ExifInterface.ORIENTATION_ROTATE_270: return 270; default: return 0; } }
From source file:Main.java
public static Bitmap rotateBitmapInNeeded(String path, Bitmap srcBitmap) { if (TextUtils.isEmpty(path) || srcBitmap == null) { return null; }/*from w w w .j a v a2 s .com*/ 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
/** * <pre>/*from www . j a v a 2 s.c o m*/ * Get rotation angle of an image. * This information is stored in image file. Therefore, this method needs path to file, not a {@link Bitmap} object or byte array. * </pre> * @param imagePath absolute path to image file * @return one of 0, 90, 180, 270 */ public static int getImageRotateAngle(String imagePath) throws IOException { ExifInterface exif = new ExifInterface(imagePath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int angle = 0; if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { angle = 90; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { angle = 180; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { angle = 270; } return angle; }
From source file:Main.java
public static int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath) { int rotate = 0; try {/*from ww w .j av a 2s . c om*/ 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 getRotatedDegree(String path) { int rotate = 0; try {/*from w w w . j a v a 2s . com*/ ExifInterface exifInterface = new ExifInterface(path); int result = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch (result) { 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: 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 {/* www . j av a2s. 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; }