List of usage examples for android.media ExifInterface ExifInterface
public ExifInterface(InputStream inputStream) throws IOException
From source file:Main.java
public static int readPictureDegree(String path) { int degree = 0; try {/*from ww w. j av a2s . c o m*/ 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
private static int getRotationFromCamera(Context context, Uri imageFile) { int rotate = 0; try {/*from w ww. j a v a 2 s . co 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
@TargetApi(Build.VERSION_CODES.ECLAIR) public static int getImageDegree(String path) { int degree = 0; try {// w w w . j av a 2s . 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
public static void removeExif(String path) { if (!TextUtils.isEmpty(path)) { return;/* w ww . j a v a2 s .co m*/ } ExifInterface exifInterface; try { exifInterface = new ExifInterface(path); } catch (IOException ignore) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { exifInterface.setAttribute(ExifInterface.TAG_ARTIST, ""); exifInterface.setAttribute(ExifInterface.TAG_RESOLUTION_UNIT, "0"); exifInterface.setAttribute(ExifInterface.TAG_DATETIME_ORIGINAL, ""); exifInterface.setAttribute(ExifInterface.TAG_MAKER_NOTE, "0"); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { exifInterface.setAttribute(ExifInterface.TAG_DATETIME_DIGITIZED, ""); } exifInterface.setAttribute(ExifInterface.TAG_MAKE, ""); exifInterface.setAttribute(ExifInterface.TAG_MODEL, ""); exifInterface.setAttribute(ExifInterface.TAG_ORIENTATION, "0"); exifInterface.setAttribute(ExifInterface.TAG_DATETIME, ""); exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE, ""); exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, ""); exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE, ""); }
From source file:Main.java
public static Bitmap rotateImage(Bitmap bitmap, String storagePath) { Bitmap resultBitmap = bitmap;//from w w w . ja v a2 s. co m try { ExifInterface exifInterface = new ExifInterface(storagePath); int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); Matrix matrix = new Matrix(); // 1: nothing to do // 2 if (orientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) { matrix.postScale(-1.0f, 1.0f); } // 3 else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { matrix.postRotate(180); } // 4 else if (orientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) { matrix.postScale(1.0f, -1.0f); } // 5 else if (orientation == ExifInterface.ORIENTATION_TRANSPOSE) { matrix.postRotate(-90); matrix.postScale(1.0f, -1.0f); } // 6 else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { matrix.postRotate(90); } // 7 else if (orientation == ExifInterface.ORIENTATION_TRANSVERSE) { matrix.postRotate(90); matrix.postScale(1.0f, -1.0f); } // 8 else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { matrix.postRotate(270); } // Rotate the bitmap resultBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); if (resultBitmap != bitmap) { bitmap.recycle(); } } catch (Exception exception) { Log.e("BitmapUtil", "Could not rotate the image: " + storagePath); } return resultBitmap; }
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 2s .c o m*/ 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
/** * Calculates the amount of rotation needed for the image to look upright. * /*from ww w . j a va 2s.c o m*/ * @param context * the application's context * @param uri * the Uri pointing to the file * @return the needed rotation as a <code>float</code> */ private static float rotationForImage(Context context, Uri uri) { if ("content".equals(uri.getScheme())) { String[] projection = { Images.ImageColumns.ORIENTATION }; Cursor c = context.getContentResolver().query(uri, projection, null, null, null); if (c.moveToFirst()) { return c.getInt(0); } } else if ("file".equals(uri.getScheme())) { try { ExifInterface exif = new ExifInterface(uri.getPath()); int rotation = (int) exifOrientationToDegrees( exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)); return rotation; } catch (IOException e) { Log.e(TAG, "Error checking exif", e); } } return 0f; }
From source file:Main.java
public static Matrix getRotationMatrixForImage(Context ctx, Uri contentUri) { String pathToImage = getAbsolutePathFromUri(ctx, contentUri); ExifInterface exif;//from w w w.j a v a 2s.c o m try { 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
/** * Load the exif tags into the passed Bundle * * @param filepath/*from w w w . j ava 2s . c o m*/ * @param out * @return true if exif tags are loaded correctly */ public static boolean loadAttributes(final String filepath, Bundle out) { ExifInterface e; try { e = new ExifInterface(filepath); } catch (IOException e1) { e1.printStackTrace(); return false; } for (String tag : EXIF_TAGS) { out.putString(tag, e.getAttribute(tag)); } return true; }
From source file:Main.java
public static int getOrientationFromExif(File imgFile) throws IOException { ExifInterface exif = new ExifInterface(imgFile.getCanonicalPath()); return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); }