Java Code Examples for android.media.ExifInterface#ORIENTATION_ROTATE_270
The following examples show how to use
android.media.ExifInterface#ORIENTATION_ROTATE_270 .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageUtils.java From Android-utils with Apache License 2.0 | 6 votes |
public static int getRotateDegree(final String filePath) { try { ExifInterface exifInterface = new ExifInterface(filePath); int orientation = exifInterface.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 -1; } }
Example 2
Source File: CropUtil.java From UltimateAndroid with Apache License 2.0 | 6 votes |
public static int getExifRotation(File imageFile) { if (imageFile == null) return 0; try { ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath()); // We only recognize a subset of orientation tag values switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) { case ExifInterface.ORIENTATION_ROTATE_90: return 90; case ExifInterface.ORIENTATION_ROTATE_180: return 180; case ExifInterface.ORIENTATION_ROTATE_270: return 270; default: return ExifInterface.ORIENTATION_UNDEFINED; } } catch (IOException e) { Log.e("Error getting Exif data", e); return 0; } }
Example 3
Source File: PhotoUtil.java From Conquer with Apache License 2.0 | 6 votes |
/** * * 读取图片属性:旋转的角度 * * @param path * 图片绝对路径 * @return degree旋转的角度 */ public static int readPictureDegree(String path) { int degree = 0; try { 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; }
Example 4
Source File: MediaUtils.java From PictureSelector with Apache License 2.0 | 6 votes |
/** * 获取旋转角度 * * @param path * @return */ public static int getVideoOrientationForUrl(String path) { try { MediaMetadataRetriever mmr = new MediaMetadataRetriever(); mmr.setDataSource(path); int rotation = ValueOf.toInt(mmr.extractMetadata (MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION)); switch (rotation) { case 90: return ExifInterface.ORIENTATION_ROTATE_90; case 270: return ExifInterface.ORIENTATION_ROTATE_270; default: return 0; } } catch (Exception e) { e.printStackTrace(); return 0; } }
Example 5
Source File: MediaUtils.java From PictureSelector with Apache License 2.0 | 6 votes |
/** * 获取旋转角度 * * @param uri * @return */ public static int getVideoOrientationForUri(Context context, Uri uri) { try { MediaMetadataRetriever mmr = new MediaMetadataRetriever(); mmr.setDataSource(context, uri); int orientation = ValueOf.toInt(mmr.extractMetadata (MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION)); switch (orientation) { case 90: return ExifInterface.ORIENTATION_ROTATE_90; case 270: return ExifInterface.ORIENTATION_ROTATE_270; default: return 0; } } catch (Exception e) { e.printStackTrace(); return 0; } }
Example 6
Source File: BitmapUtils.java From CameraCardCropDemo with Apache License 2.0 | 6 votes |
private static int getExifRotateDegrees(int exifOrientation) { int degrees = 0; switch (exifOrientation) { case ExifInterface.ORIENTATION_NORMAL: degrees = 0; break; case ExifInterface.ORIENTATION_ROTATE_90: degrees = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degrees = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degrees = 270; break; } return degrees; }
Example 7
Source File: FilesUtils.java From PocketEOS-Android with GNU Lesser General Public License v3.0 | 6 votes |
/** * 读取图片的旋转的角度 * * @param path 图片绝对路径 * @return 图片的旋转角度 bitmap degree */ public static int getBitmapDegree(String path) { int degree = 0; try { // 从指定路径下读取图片,并获取其EXIF信息 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; }
Example 8
Source File: BitmapUtil.java From Matisse with Apache License 2.0 | 6 votes |
/** * 获取图片的旋转角度 * * @param path 图片绝对路径 * @return 图片的旋转角度 */ public static int getBitmapDegree(String path) { int degree = 0; try { // 从指定路径下读取图片,并获取其EXIF信息 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; }
Example 9
Source File: Utils.java From ObservableScheduler with Apache License 2.0 | 6 votes |
private static int readPictureDegree(String path) { int degree = 0; try { 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; }
Example 10
Source File: Fetcher.java From tns-core-modules-widgets with Apache License 2.0 | 6 votes |
private static int calculateRotationAngle(ExifInterface ei) { int rotationAngle = 0; final int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotationAngle = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotationAngle = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: rotationAngle = 270; break; } return rotationAngle; }
Example 11
Source File: BitmapUtil.java From AndroidStudyDemo with GNU General Public License v2.0 | 6 votes |
/** * 读取图片属性:图片被旋转的角度 * * @param path 图片绝对路径 * @return 旋转的角度 */ public static int getImageDegree(String path) { int degree = 0; try { 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; }
Example 12
Source File: PictureFileUtils.java From smart-farmer-android with Apache License 2.0 | 6 votes |
/** * 读取图片属性:旋转的角度 * * @param path 图片绝对路径 * @return degree旋转的角度 */ public static int readPictureDegree(String path) { int degree = 0; try { 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; default: break; } } catch (IOException e) { e.printStackTrace(); } return degree; }
Example 13
Source File: VMBitmap.java From VMLibrary with Apache License 2.0 | 6 votes |
/** * 获取图片的旋转角度 * * @param path 图片绝对路径 * @return 图片的旋转角度 */ public static int getBitmapDegree(String path) { int degree = 0; try { // 从指定路径下读取图片,并获取其EXIF信息 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; }
Example 14
Source File: Luban.java From AndroidBase with Apache License 2.0 | 6 votes |
/** * obtain the image rotation angle * * @param path path of target image */ private int getImageSpinAngle(String path) { int degree = 0; try { 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; }
Example 15
Source File: Utils.java From Android-CropView with Apache License 2.0 | 5 votes |
public static Matrix getMatrixFromExifOrientation(int orientation) { Matrix matrix = new Matrix(); switch (orientation) { case ExifInterface.ORIENTATION_UNDEFINED: break; case ExifInterface.ORIENTATION_NORMAL: break; case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: matrix.postScale(-1.0f, 1.0f); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.postRotate(180.0f); break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: matrix.postScale(1.0f, -1.0f); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.postRotate(90.0f); break; case ExifInterface.ORIENTATION_TRANSVERSE: matrix.postRotate(-90.0f); matrix.postScale(1.0f, -1.0f); break; case ExifInterface.ORIENTATION_TRANSPOSE: matrix.postRotate(90.0f); matrix.postScale(1.0f, -1.0f); break; case ExifInterface.ORIENTATION_ROTATE_270: matrix.postRotate(-90.0f); break; } return matrix; }
Example 16
Source File: MediaUtils.java From PictureSelector with Apache License 2.0 | 5 votes |
/** * 设置LocalMedia旋转信息 * * @param context * @param media * @param isAndroidQChangeWH * @return */ public static void setOrientationSynchronous(Context context, LocalMedia media, boolean isAndroidQChangeWH, boolean isAndroidQChangeVideoWH) { if (PictureMimeType.isHasImage(media.getMimeType())) { if (!isAndroidQChangeWH) { return; } } if (PictureMimeType.isHasVideo(media.getMimeType())) { if (!isAndroidQChangeVideoWH) { return; } } // 如果有旋转信息图片宽高则是相反 int orientation = 0; if (PictureMimeType.isHasImage(media.getMimeType())) { orientation = MediaUtils.getImageOrientationForUrl(context, media.getPath()); } else if (PictureMimeType.isHasVideo(media.getMimeType())) { if (PictureMimeType.isContent(media.getPath())) { orientation = MediaUtils.getVideoOrientationForUri(context, Uri.parse(media.getPath())); } else { orientation = MediaUtils.getVideoOrientationForUrl(media.getPath()); } } if (orientation == ExifInterface.ORIENTATION_ROTATE_90 || orientation == ExifInterface.ORIENTATION_ROTATE_270) { int width = media.getWidth(); int height = media.getHeight(); media.setWidth(height); media.setHeight(width); } media.setOrientation(orientation); }
Example 17
Source File: ImageUtils.java From FaceDetectCamera with Apache License 2.0 | 5 votes |
public static Bitmap getBitmap(String filePath, int width, int height) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, options); options.inSampleSize = ImageUtils.calculateInSampleSize(options, width, height); options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; Bitmap bitmap = BitmapFactory.decodeFile(filePath, options); if (bitmap != null) { try { ExifInterface ei = new ExifInterface(filePath); int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: bitmap = ImageUtils.rotate(bitmap, 90); break; case ExifInterface.ORIENTATION_ROTATE_180: bitmap = ImageUtils.rotate(bitmap, 180); break; case ExifInterface.ORIENTATION_ROTATE_270: bitmap = ImageUtils.rotate(bitmap, 270); break; // etc. } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return bitmap; }
Example 18
Source File: DngCreator.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Set the orientation value to write. * * <p> * This will be written as the TIFF "Orientation" tag {@code (0x0112)}. * Calling this will override any prior settings for this tag. * </p> * * @param orientation the orientation value to set, one of: * <ul> * <li>{@link android.media.ExifInterface#ORIENTATION_NORMAL}</li> * <li>{@link android.media.ExifInterface#ORIENTATION_FLIP_HORIZONTAL}</li> * <li>{@link android.media.ExifInterface#ORIENTATION_ROTATE_180}</li> * <li>{@link android.media.ExifInterface#ORIENTATION_FLIP_VERTICAL}</li> * <li>{@link android.media.ExifInterface#ORIENTATION_TRANSPOSE}</li> * <li>{@link android.media.ExifInterface#ORIENTATION_ROTATE_90}</li> * <li>{@link android.media.ExifInterface#ORIENTATION_TRANSVERSE}</li> * <li>{@link android.media.ExifInterface#ORIENTATION_ROTATE_270}</li> * </ul> * @return this {@link #DngCreator} object. */ @NonNull public DngCreator setOrientation(int orientation) { if (orientation < ExifInterface.ORIENTATION_UNDEFINED || orientation > ExifInterface.ORIENTATION_ROTATE_270) { throw new IllegalArgumentException("Orientation " + orientation + " is not a valid EXIF orientation value"); } // ExifInterface and TIFF/EP spec differ on definition of // "Unknown" orientation; other values map directly if (orientation == ExifInterface.ORIENTATION_UNDEFINED) { orientation = TAG_ORIENTATION_UNKNOWN; } nativeSetOrientation(orientation); return this; }
Example 19
Source File: ImageUtils.java From phoenix with Apache License 2.0 | 4 votes |
private Bitmap rotateBitmap(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); 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 ignore) { return null; } }
Example 20
Source File: BitmapUtils.java From Cirrus_depricated with GNU General Public License v2.0 | 4 votes |
/** * Rotate bitmap according to EXIF orientation. * Cf. http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ * @param bitmap Bitmap to be rotated * @param storagePath Path to source file of bitmap. Needed for EXIF information. * @return correctly EXIF-rotated bitmap */ public static Bitmap rotateImage(Bitmap bitmap, String storagePath){ Bitmap resultBitmap = bitmap; 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_OC.e("BitmapUtil", "Could not rotate the image: " + storagePath); } return resultBitmap; }