Java Code Examples for android.media.ExifInterface#getAttributeInt()
The following examples show how to use
android.media.ExifInterface#getAttributeInt() .
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: CropUtil.java From LockDemo 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 2
Source File: CropUtil.java From XERUNG 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 LoveTalkClient 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: BitmapUtils.java From VideoMeeting with Apache License 2.0 | 6 votes |
public static int getImageOrientation(String imagePath) { try { if(imagePath != null){ ExifInterface exif = new ExifInterface(imagePath); int orientation = exif.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; } } } catch (IOException e) { } return 0; }
Example 5
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 6
Source File: MainActivity.java From journaldev with MIT License | 6 votes |
private static Bitmap rotateImageIfRequired(Bitmap img, Uri selectedImage) throws IOException { ExifInterface ei = new ExifInterface(selectedImage.getPath()); int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: return rotateImage(img, 90); case ExifInterface.ORIENTATION_ROTATE_180: return rotateImage(img, 180); case ExifInterface.ORIENTATION_ROTATE_270: return rotateImage(img, 270); default: return img; } }
Example 7
Source File: BitmapUtil.java From imsdk-android with MIT License | 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 8
Source File: BitmapUtil.java From RichEditor with MIT License | 6 votes |
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: degree = 0; break; } } catch (IOException e) { e.printStackTrace(); } return degree; }
Example 9
Source File: PhotoUtils.java From MyBlogDemo with Apache License 2.0 | 6 votes |
/** * 获取图片的旋转角度 * * @param path 图片的绝对路径 * @return 图片的旋转角度 */ private 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 10
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 11
Source File: BitmapUtils.java From timecat with Apache License 2.0 | 6 votes |
/** * Rotate the given image by given Exif value.<br> * If no rotation is required the image will not be rotated.<br> * New bitmap is created and the old one is recycled. */ static RotateBitmapResult rotateBitmapByExif(Bitmap bitmap, ExifInterface exif) { int degrees; int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: degrees = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degrees = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degrees = 270; break; default: degrees = 0; break; } return new RotateBitmapResult(bitmap, degrees); }
Example 12
Source File: FileRequestHandler.java From DoraemonKit with Apache License 2.0 | 5 votes |
static int getFileExifRotation(Uri uri) throws IOException { ExifInterface exifInterface = new ExifInterface(uri.getPath()); int orientation = exifInterface.getAttributeInt(TAG_ORIENTATION, ORIENTATION_NORMAL); switch (orientation) { case ORIENTATION_ROTATE_90: return 90; case ORIENTATION_ROTATE_180: return 180; case ORIENTATION_ROTATE_270: return 270; default: return 0; } }
Example 13
Source File: BaseImageDecoder.java From Roid-Library with Apache License 2.0 | 5 votes |
protected ExifInfo defineExifOrientation(String imageUri, String mimeType) { int rotation = 0; boolean flip = false; if ("image/jpeg".equalsIgnoreCase(mimeType) && Scheme.ofUri(imageUri) == Scheme.FILE) { try { ExifInterface exif = new ExifInterface(Scheme.FILE.crop(imageUri)); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exifOrientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: flip = true; case ExifInterface.ORIENTATION_NORMAL: rotation = 0; break; case ExifInterface.ORIENTATION_TRANSVERSE: flip = true; case ExifInterface.ORIENTATION_ROTATE_90: rotation = 90; break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: flip = true; case ExifInterface.ORIENTATION_ROTATE_180: rotation = 180; break; case ExifInterface.ORIENTATION_TRANSPOSE: flip = true; case ExifInterface.ORIENTATION_ROTATE_270: rotation = 270; break; } } catch (IOException e) { L.w("Can't read EXIF tags from file [%s]", imageUri); } } return new ExifInfo(rotation, flip); }
Example 14
Source File: DiskDecoder.java From talk-android with MIT License | 5 votes |
protected ExifInfo defineExifOrientation(String imageUri) { int rotation = 0; boolean flip = false; try { ExifInterface exif = new ExifInterface(ImageDownloader.Scheme.FILE.crop(imageUri)); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exifOrientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: flip = true; case ExifInterface.ORIENTATION_NORMAL: rotation = 0; break; case ExifInterface.ORIENTATION_TRANSVERSE: flip = true; case ExifInterface.ORIENTATION_ROTATE_90: rotation = 90; break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: flip = true; case ExifInterface.ORIENTATION_ROTATE_180: rotation = 180; break; case ExifInterface.ORIENTATION_TRANSPOSE: flip = true; case ExifInterface.ORIENTATION_ROTATE_270: rotation = 270; break; } } catch (IOException e) { L.w("Can't read EXIF tags from file [%s]", imageUri); } return new ExifInfo(rotation, flip); }
Example 15
Source File: ContactEditorFragment.java From linphone-android with GNU General Public License v3.0 | 4 votes |
private void editContactPicture(String filePath, Bitmap image) { int orientation = ExifInterface.ORIENTATION_NORMAL; if (image == null) { Log.i( "[Contact Editor] Bitmap is null, trying to decode image from file [", filePath, "]"); image = BitmapFactory.decodeFile(filePath); try { ExifInterface ei = new ExifInterface(filePath); orientation = ei.getAttributeInt( ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); Log.i("[Contact Editor] Exif rotation is ", orientation); } catch (IOException e) { Log.e("[Contact Editor] Failed to get Exif rotation, error is ", e); } } else { } if (image == null) { Log.e( "[Contact Editor] Couldn't get bitmap from either filePath [", filePath, "] nor image"); return; } switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: image = ImageUtils.rotateImage(image, 90); break; case ExifInterface.ORIENTATION_ROTATE_180: image = ImageUtils.rotateImage(image, 180); break; case ExifInterface.ORIENTATION_ROTATE_270: image = ImageUtils.rotateImage(image, 270); break; case ExifInterface.ORIENTATION_NORMAL: // Nothing to do break; default: Log.w("[Contact Editor] Unexpected orientation ", orientation); } ByteArrayOutputStream stream = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.JPEG, 100, stream); mPhotoToAdd = stream.toByteArray(); Bitmap roundPicture = ImageUtils.getRoundBitmap(image); ContactAvatar.displayAvatar(roundPicture, mView.findViewById(R.id.avatar_layout)); image.recycle(); }
Example 16
Source File: CropImageView.java From PhotoEdit with Apache License 2.0 | 4 votes |
/** * Sets a Bitmap and initializes the image rotation according to the EXIT data. * <p> * The EXIF can be retrieved by doing the following: * <code>ExifInterface exif = new ExifInterface(path);</code> * * @param bitmap the original bitmap to set; if null, this * @param exif the EXIF information about this bitmap; may be null */ public void setImageBitmap(Bitmap bitmap, ExifInterface exif) { if (bitmap == null) { return; } if (exif == null) { setImageBitmap(bitmap); return; } final Matrix matrix = new Matrix(); final int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); int rotate = -1; 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; } if (rotate == -1) { setImageBitmap(bitmap); } else { matrix.postRotate(rotate); final Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); setImageBitmap(rotatedBitmap); bitmap.recycle(); } }
Example 17
Source File: CropImageView.java From PictureChooseLib with Apache License 2.0 | 4 votes |
/** * Sets a Bitmap and initializes the image rotation according to the EXIT data. * <p> * The EXIF can be retrieved by doing the following: * <code>ExifInterface exif = new ExifInterface(path);</code> * * @param bitmap the original bitmap to set; if null, this * @param exif the EXIF information about this bitmap; may be null */ public void setImageBitmap(Bitmap bitmap, ExifInterface exif) { if (bitmap == null) { return; } if (exif == null) { setImageBitmap(bitmap); return; } final Matrix matrix = new Matrix(); final int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); int rotate = -1; 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; } if (rotate == -1) { setImageBitmap(bitmap); } else { matrix.postRotate(rotate); final Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); setImageBitmap(rotatedBitmap); bitmap.recycle(); } }
Example 18
Source File: GlideImageJob.java From hipda with GNU General Public License v2.0 | 4 votes |
private void processFile(ImageInfo imageInfo, File cacheFile) { if (!imageInfo.isSuccess()) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; //Returns null, sizes are in the options variable BitmapFactory.decodeFile(cacheFile.getPath(), options); int width = options.outWidth; int height = options.outHeight; String mime = Utils.nullToText(options.outMimeType); int orientation = 0; if (mime.toLowerCase().contains("jpeg") || mime.toLowerCase().contains("jpg") || mime.toLowerCase().contains("png")) { try { ExifInterface exif = new ExifInterface(cacheFile.getPath()); orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0); } catch (Exception e) { Logger.e(e); } } if (orientation == ExifInterface.ORIENTATION_ROTATE_90 || orientation == ExifInterface.ORIENTATION_ROTATE_270) { width = options.outHeight; height = options.outWidth; } imageInfo.setStatus(ImageInfo.SUCCESS); imageInfo.setProgress(100); imageInfo.setPath(cacheFile.getPath()); imageInfo.setWidth(width); imageInfo.setHeight(height); imageInfo.setMime(mime); imageInfo.setFileSize(cacheFile.length()); if (orientation > 0) imageInfo.setOrientation(orientation); ImageContainer.markImageReady(mUrl, imageInfo); } EventBus.getDefault().post(new GlideImageEvent(mUrl, 100, ImageInfo.SUCCESS)); }
Example 19
Source File: CropImageView.java From Favorite-Android-Client with Apache License 2.0 | 4 votes |
/** * Sets a Bitmap and initializes the image rotation according to the EXIT data. * <p> * The EXIF can be retrieved by doing the following: * <code>ExifInterface exif = new ExifInterface(path);</code> * * @param bitmap the original bitmap to set; if null, this * @param exif the EXIF information about this bitmap; may be null */ public void setImageBitmap(Bitmap bitmap, ExifInterface exif) { if (bitmap == null) { return; } if (exif == null) { setImageBitmap(bitmap); return; } final Matrix matrix = new Matrix(); final int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); int rotate = -1; 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; } if (rotate == -1) { setImageBitmap(bitmap); } else { matrix.postRotate(rotate); final Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); setImageBitmap(rotatedBitmap); bitmap.recycle(); } }
Example 20
Source File: MainActivity.java From MOAAP with MIT License | 4 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == ACTION_PICK_PHOTO && resultCode == RESULT_OK && null != data && read_external_storage_granted) { Uri selectedImage = data.getData(); String[] filePathColumn = {MediaStore.Images.Media.DATA}; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); String picturePath; if(cursor == null) { Log.i("data", "cannot load any image"); return; }else { try { cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); picturePath = cursor.getString(columnIndex); }finally { cursor.close(); } } BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; Bitmap temp = BitmapFactory.decodeFile(picturePath, options); int orientation = 0; try { ExifInterface imgParams = new ExifInterface(picturePath); orientation = imgParams.getAttributeInt( ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); } catch (IOException e) { e.printStackTrace(); } Matrix rotate90 = new Matrix(); rotate90.postRotate(orientation); Bitmap originalBitmap = rotateBitmap(temp,orientation); if(originalBitmap != null) { Bitmap tempBitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, true); originalMat = new Mat(tempBitmap.getHeight(), tempBitmap.getWidth(), CvType.CV_8U); Utils.bitmapToMat(tempBitmap, originalMat); currentBitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, false); imageView.setImageBitmap(currentBitmap); }else { Log.i("data", "originalBitmap is empty"); } } }