List of usage examples for android.media ExifInterface ORIENTATION_ROTATE_270
int ORIENTATION_ROTATE_270
To view the source code for android.media ExifInterface ORIENTATION_ROTATE_270.
Click Source Link
From source file:Main.java
/** * Return the string representation of the given orientation * * @param orientation//from w w w.ja v a 2 s.c o m * @return */ public static String getExifOrientation(int orientation) { switch (orientation) { case 0: return String.valueOf(ExifInterface.ORIENTATION_NORMAL); case 90: return String.valueOf(ExifInterface.ORIENTATION_ROTATE_90); case 180: return String.valueOf(ExifInterface.ORIENTATION_ROTATE_180); case 270: return String.valueOf(ExifInterface.ORIENTATION_ROTATE_270); default: throw new AssertionError("invalid: " + orientation); } }
From source file:Main.java
public static Bitmap rotateImage(Bitmap bitmap, String storagePath) { Bitmap resultBitmap = bitmap;//from w w w. j av a 2s. 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 readPictureDegree(String path) { int degree = 0; try {//from w w w . j a v a 2s. com 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 decodeExifBitmap(File file, Bitmap src) { try {//from w w w .j a v a2 s . co m // Try to load the bitmap as a bitmap file ExifInterface exif = new ExifInterface(file.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); if (orientation == ExifInterface.ORIENTATION_UNDEFINED || orientation == ExifInterface.ORIENTATION_NORMAL) { return src; } 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); } else if (orientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) { matrix.setScale(-1, 1); matrix.postTranslate(src.getWidth(), 0); } else if (orientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) { matrix.setScale(1, -1); matrix.postTranslate(0, src.getHeight()); } // Rotate the bitmap return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); } catch (IOException e) { // Ignore } return src; }
From source file:Main.java
public static int readPictureDegree(String filename) { short degree = 0; try {/*from ww w.j ava 2 s.c o m*/ ExifInterface exifInterface = new ExifInterface(filename); int anInt = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); switch (anInt) { case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; case ExifInterface.ORIENTATION_FLIP_VERTICAL: case ExifInterface.ORIENTATION_TRANSPOSE: case ExifInterface.ORIENTATION_TRANSVERSE: default: break; case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; } } catch (IOException e) { e.printStackTrace(); } return degree; }
From source file:Main.java
private static int getImageRotationAngle(Uri imageUri, ContentResolver contentResolver) throws IOException { int angle = 0; Cursor cursor = contentResolver.query(imageUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);/*from w ww . ja v a2 s. c o m*/ if (cursor != null) { if (cursor.getCount() == 1) { cursor.moveToFirst(); angle = cursor.getInt(0); } cursor.close(); } else { ExifInterface exif = new ExifInterface(imageUri.getPath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: angle = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: angle = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: angle = 90; break; default: break; } } return angle; }
From source file:Main.java
public static int getExifOrientation(String filepath) { int degree = 0; ExifInterface exif = null;/*from w w w. j a v a2s . c o m*/ try { exif = new ExifInterface(filepath); } catch (IOException ex) { Log.e(TAG, "cannot read exif", ex); } if (exif != null) { int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); if (orientation != -1) { // We only recognize a subset of orientation tag values. 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; } } } return degree; }
From source file:mobisocial.noteshere.util.UriImage.java
private static float exifOrientationToDegrees(int exifOrientation) { if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { return 180; } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { return 270; }//from w w w.ja v a2s.c o m return 0; }
From source file:com.exzogeni.dk.graphics.Bitmaps.java
@NonNull private static Matrix getExifMatrix(int orientation) { final Matrix matrix = new Matrix(); if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { matrix.setRotate(180);/*from w w w .ja va 2 s.c o m*/ } else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { matrix.setRotate(90); } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { matrix.setRotate(-90); } return matrix; }
From source file:com.haru.ui.image.workers.MediaProcessorThread.java
private String compressAndSaveImage(String fileImage, int scale) throws Exception { try {//from w w w. j a v a 2 s. c o m ExifInterface exif = new ExifInterface(fileImage); String width = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String length = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int rotate = 0; if (/* TODO: DEBUG */ true) { Log.i(TAG, "Before: " + width + "x" + length); } switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = -90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; } int w = Integer.parseInt(width); int l = Integer.parseInt(length); int what = w > l ? w : l; Options options = new Options(); if (what > 1500) { options.inSampleSize = scale * 4; } else if (what > 1000 && what <= 1500) { options.inSampleSize = scale * 3; } else if (what > 400 && what <= 1000) { options.inSampleSize = scale * 2; } else { options.inSampleSize = scale; } if (/* TODO: DEBUG */ true) { Log.i(TAG, "Scale: " + (what / options.inSampleSize)); Log.i(TAG, "Rotate: " + rotate); } Bitmap bitmap = BitmapFactory.decodeFile(fileImage, options); File original = new File(fileImage); File file = new File((original.getParent() + File.separator + original.getName().replace(".", "_fact_" + scale + "."))); FileOutputStream stream = new FileOutputStream(file); if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); } bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); if (/* TODO: DEBUG */ true) { ExifInterface exifAfter = new ExifInterface(file.getAbsolutePath()); String widthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String lengthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); if (/* TODO: DEBUG */ true) { Log.i(TAG, "After: " + widthAfter + "x" + lengthAfter); } } stream.flush(); stream.close(); return file.getAbsolutePath(); } catch (IOException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw new Exception("Corrupt or deleted file???"); } }