List of usage examples for android.media ExifInterface ORIENTATION_TRANSVERSE
int ORIENTATION_TRANSVERSE
To view the source code for android.media ExifInterface ORIENTATION_TRANSVERSE.
Click Source Link
From source file:Main.java
public static int exifToTranslation(int exifOrientation) { int translation; switch (exifOrientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: case ExifInterface.ORIENTATION_FLIP_VERTICAL: case ExifInterface.ORIENTATION_TRANSPOSE: case ExifInterface.ORIENTATION_TRANSVERSE: translation = -1;/*from w w w.ja v a 2s.c om*/ break; default: translation = 1; } return translation; }
From source file:Main.java
private static int exifToTranslation(int exifOrientation) { int translation; switch (exifOrientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: case ExifInterface.ORIENTATION_FLIP_VERTICAL: case ExifInterface.ORIENTATION_TRANSPOSE: case ExifInterface.ORIENTATION_TRANSVERSE: translation = -1;// w ww.ja v a 2 s. c o m break; default: translation = 1; } return translation; }
From source file:Main.java
public static int[] getRotation(String imgPath) { int[] rs = new int[2]; int rotation = 0; int flip = 0; try {/*w ww. j av a 2 s .c o m*/ ExifInterface exif = new ExifInterface(imgPath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exifOrientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: flip = 1; case ExifInterface.ORIENTATION_NORMAL: rotation = 0; break; case ExifInterface.ORIENTATION_TRANSVERSE: flip = 1; case ExifInterface.ORIENTATION_ROTATE_90: rotation = 90; break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: flip = 1; case ExifInterface.ORIENTATION_ROTATE_180: rotation = 180; break; case ExifInterface.ORIENTATION_TRANSPOSE: flip = 1; case ExifInterface.ORIENTATION_ROTATE_270: rotation = 270; break; } } catch (IOException e) { e.printStackTrace(); } rs[0] = rotation; rs[1] = flip; return rs; }
From source file:Main.java
/** * Get the # of degrees an image must be rotated to match the given exif orientation. * * @param exifOrientation The exif orientation [1-8] * @return the number of degrees to rotate *///from ww w . j a v a 2 s . c o m public static int getExifOrientationDegrees(int exifOrientation) { final int degreesToRotate; switch (exifOrientation) { case ExifInterface.ORIENTATION_TRANSPOSE: case ExifInterface.ORIENTATION_ROTATE_90: degreesToRotate = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: case ExifInterface.ORIENTATION_FLIP_VERTICAL: degreesToRotate = 180; break; case ExifInterface.ORIENTATION_TRANSVERSE: case ExifInterface.ORIENTATION_ROTATE_270: degreesToRotate = 270; break; default: degreesToRotate = 0; } return degreesToRotate; }
From source file:Main.java
/** * Get the # of degrees an image must be rotated to match the given exif orientation. * * @param exifOrientation The exif orientation [1-8] * @return the number of degrees to rotate *//* w ww. ja v a2 s . co m*/ public static int getExifOrientationDegrees(int exifOrientation) { final int degreesToRotate; switch (exifOrientation) { case ExifInterface.ORIENTATION_TRANSPOSE: case ExifInterface.ORIENTATION_ROTATE_90: degreesToRotate = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: case ExifInterface.ORIENTATION_FLIP_VERTICAL: degreesToRotate = 180; break; case ExifInterface.ORIENTATION_TRANSVERSE: case ExifInterface.ORIENTATION_ROTATE_270: degreesToRotate = 270; break; default: degreesToRotate = 0; break; } return degreesToRotate; }
From source file:Main.java
public static Bitmap normalizeExifRotateBitmap(Bitmap bitmap, int orientation) { Matrix matrix = new Matrix(); switch (orientation) { case ExifInterface.ORIENTATION_NORMAL: return bitmap; case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: matrix.setScale(-1, 1);//from www . ja va2 s . co m break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.setRotate(180); break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: matrix.setRotate(180); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_TRANSPOSE: matrix.setRotate(90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.setRotate(90); break; case ExifInterface.ORIENTATION_TRANSVERSE: matrix.setRotate(-90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_270: matrix.setRotate(-90); break; default: return bitmap; } try { Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); bitmap.recycle(); return bmRotated; } catch (OutOfMemoryError 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 www . j a v a 2 s . 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
public static Bitmap rotateBitmap(Bitmap bitmap, int exifOrientation) { Matrix matrix = new Matrix(); switch (exifOrientation) { case ExifInterface.ORIENTATION_NORMAL: default://from w ww .ja v a2 s. co m return bitmap; case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: matrix.setScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.setRotate(180); break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: matrix.setRotate(180); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_TRANSPOSE: matrix.setRotate(90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.setRotate(90); break; case ExifInterface.ORIENTATION_TRANSVERSE: matrix.setRotate(-90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_270: matrix.setRotate(-90); break; } try { return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } catch (OutOfMemoryError e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static Bitmap rotateImage(Bitmap bitmap, String storagePath) { Bitmap resultBitmap = bitmap;//from w w w . j ava2s .c o 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 void fixBitmapRotationExif(String filePath, Activity activityForScreenOrientation) { try {/* w w w.j a v a 2 s . co m*/ ExifInterface exif = new ExifInterface(filePath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); if (exifOrientation == ExifInterface.ORIENTATION_UNDEFINED && Build.MANUFACTURER.toLowerCase(Locale.ENGLISH).contains("htc")) return; boolean flippedHorizontally = false, flippedVertically = false; int angle = 0; if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { angle += 90; } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { angle += 180; } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { angle += 270; } else if (exifOrientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) { flippedHorizontally = true; } else if (exifOrientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) { flippedVertically = true; } else if (exifOrientation == ExifInterface.ORIENTATION_TRANSPOSE) { angle += 90; flippedVertically = true; } else if (exifOrientation == ExifInterface.ORIENTATION_TRANSVERSE) { angle -= 90; flippedVertically = true; } int orientation; if (activityForScreenOrientation != null) { orientation = getScreenOrientation(activityForScreenOrientation); if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { angle += 90; } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) { angle += 180; } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) { angle += 270; } } orientation = 0; angle = angle % 360; if (angle == -90 && flippedVertically && !flippedHorizontally) { orientation = ExifInterface.ORIENTATION_TRANSVERSE; } else if (angle == -270 && flippedVertically && !flippedHorizontally) { orientation = ExifInterface.ORIENTATION_TRANSPOSE; } else if (angle == -90 && !flippedVertically && flippedHorizontally) { orientation = ExifInterface.ORIENTATION_TRANSPOSE; } else if (angle == -270 && !flippedVertically && flippedHorizontally) { orientation = ExifInterface.ORIENTATION_TRANSVERSE; } else { while (angle < 0) { angle += 360; } switch (angle) { case 0: if (flippedHorizontally) { orientation = ExifInterface.ORIENTATION_FLIP_HORIZONTAL; } else if (flippedVertically) { orientation = ExifInterface.ORIENTATION_FLIP_VERTICAL; } break; case 90: orientation = ExifInterface.ORIENTATION_ROTATE_90; break; case 180: orientation = ExifInterface.ORIENTATION_ROTATE_180; break; case 270: orientation = ExifInterface.ORIENTATION_ROTATE_270; break; } } if (orientation != exifOrientation) { exif.setAttribute(ExifInterface.TAG_ORIENTATION, ((Integer) orientation).toString()); exif.saveAttributes(); } } catch (IOException e) { Log.w("TAG", "-- Error in setting image"); } }