List of usage examples for android.media ExifInterface getAttributeInt
public int getAttributeInt(String tag, int defaultValue)
From source file:com.pdftron.pdf.utils.ViewerUtils.java
public static Map readImageIntent(Intent data, Context context, Uri outputFileUri) throws FileNotFoundException, Exception { final boolean isCamera; if (data == null || data.getData() == null) { isCamera = true;/* w w w.j av a2 s .co m*/ } else { final String action = data.getAction(); if (action == null) { isCamera = false; } else { isCamera = action.equals(MediaStore.ACTION_IMAGE_CAPTURE); } } Uri imageUri; if (isCamera) { imageUri = outputFileUri; AnalyticsHandlerAdapter.getInstance().sendEvent(AnalyticsHandlerAdapter.CATEGORY_FILEBROWSER, "Create new document from camera selected"); } else { imageUri = data.getData(); AnalyticsHandlerAdapter.getInstance().sendEvent(AnalyticsHandlerAdapter.CATEGORY_FILEBROWSER, "Create new document from local image file selected"); } String filePath; if (isCamera) { filePath = imageUri.getPath(); } else { filePath = Utils.getRealPathFromImageURI(context, imageUri); if (Utils.isNullOrEmpty(filePath)) { filePath = imageUri.getPath(); } } // try to get bitmap Bitmap bitmap = Utils.getBitmapFromImageUri(context, imageUri, filePath); // if a file is selected, check if it is an image file if (!isCamera) { // if type is null if (context.getContentResolver().getType(imageUri) == null) { String extension = MimeTypeMap.getFileExtensionFromUrl(imageUri.getPath()); final String[] extensions = { "jpeg", "jpg", "tiff", "tif", "gif", "png", "bmp" }; // if file extension is not an image extension if (!Arrays.asList(extensions).contains(extension) && extension != null && !extension.equals("")) { throw new FileNotFoundException("file extension is not an image extension"); } // if type is not an image } else if (!context.getContentResolver().getType(imageUri).startsWith("image/")) { throw new FileNotFoundException("type is not an image"); } } ////////////////// Determine if image needs to be rotated /////////////////// File imageFile = new File(imageUri.getPath()); ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); int imageRotation = 0; switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: imageRotation = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: imageRotation = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: imageRotation = 90; break; } // in some devices (mainly Samsung), the EXIF is not saved with the image so look at the content // resolver as a second source of the image's rotation if (imageRotation == 0) { String[] orientationColumn = { MediaStore.Images.Media.ORIENTATION }; Cursor cur = context.getContentResolver().query(imageUri, orientationColumn, null, null, null); orientation = -1; if (cur != null && cur.moveToFirst()) { orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0])); } if (orientation > 0) { imageRotation = orientation; } } if (imageRotation != 0) { Matrix matrix = new Matrix(); matrix.postRotate(imageRotation); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } Map<String, Object> output = new HashMap<>(); output.put("bitmap", bitmap); output.put("uri", imageUri); output.put("path", filePath); output.put("camera", isCamera); return output; }
From source file:com.silentcircle.common.util.ViewUtil.java
/** * Finds JPEG image rotation flags from exif and returns matrix to be used to rotate image. * * @param fileName JPEG image file name. * * @return Matrix to use in image rotate transformation or null if parsing failed. */// w w w.j a va 2s. com public static Matrix getRotationMatrixFromExif(final String fileName) { Matrix matrix = null; try { ExifInterface exif = new ExifInterface(fileName); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int rotate = 0; switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotate = ROTATE_90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = ROTATE_180; break; case ExifInterface.ORIENTATION_ROTATE_270: rotate = ROTATE_270; break; } if (rotate != 0) { matrix = new Matrix(); matrix.preRotate(rotate); } } catch (IOException e) { Log.i(TAG, "Failed to determine image flags from file " + fileName); } return matrix; }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java
public static Bitmap decodeSampledBitmapFromPath(String path, int reqWidth, int reqHeight) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//from w ww .jav a 2 s. c om BitmapFactory.decodeFile(path, options); options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inJustDecodeBounds = false; Bitmap b = BitmapFactory.decodeFile(path, options); ExifInterface exif; try { exif = new ExifInterface(path); } catch (IOException e) { return null; } int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); Matrix matrix = new Matrix(); if (orientation == 6) matrix.postRotate(90); else if (orientation == 3) matrix.postRotate(180); else if (orientation == 8) matrix.postRotate(270); return Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true); }
From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java
private static Bitmap rotate(String path, Bitmap bm) { if (bm == null) { return null; }/*from w w w. j av a 2 s .c o m*/ Bitmap result = bm; int ori = ExifInterface.ORIENTATION_NORMAL; try { ExifInterface ei = new ExifInterface(path); ori = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); } catch (Exception e) { //simply fallback to normal orientation AQUtility.debug(e); } if (ori > 0) { Matrix matrix = getRotateMatrix(ori); result = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); AQUtility.debug("before", bm.getWidth() + ":" + bm.getHeight()); AQUtility.debug("after", result.getWidth() + ":" + result.getHeight()); if (bm != result) { bm.recycle(); } } return result; }
From source file:com.bai.android.ui.OtherActivity.java
private static int getOrientationFromFile(String imagePath) { int orientation = ExifInterface.ORIENTATION_NORMAL; int rotation; // get orientation of file try {/*w w w. j a va2 s. c o m*/ ExifInterface exif = new ExifInterface(imagePath); orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); } catch (IOException e) { e.printStackTrace(); } // set the rotation from the file orientation switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotation = 90; break; case ExifInterface.ORIENTATION_ROTATE_270: rotation = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: rotation = 180; break; default: rotation = ExifInterface.ORIENTATION_NORMAL; break; } return rotation; }
From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java
private static Bitmap rotate(String path, Bitmap bm) { if (bm == null) return null; Bitmap result = bm;//from w ww.j a v a 2 s . c om int ori = ExifInterface.ORIENTATION_NORMAL; try { ExifInterface ei = new ExifInterface(path); ori = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); } catch (Exception e) { //simply fallback to normal orientation AQUtility.debug(e); } if (ori > 0) { Matrix matrix = getRotateMatrix(ori); result = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); AQUtility.debug("before", bm.getWidth() + ":" + bm.getHeight()); AQUtility.debug("after", result.getWidth() + ":" + result.getHeight()); if (bm != result) { bm.recycle(); } } return result; }
From source file:com.angrystone.JpegExifReader.java
@Override public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; Integer result = 0;/*from ww w . ja va2 s . co m*/ if (action.equals("getWidth")) { String file = null; try { file = args.getString(0); } catch (JSONException e) { e.printStackTrace(); } try { ExifInterface exif = new ExifInterface(file); result = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (action.equals("getLength")) { String file = null; try { file = args.getString(0); } catch (JSONException e) { e.printStackTrace(); } try { ExifInterface exif = new ExifInterface(file); result = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0); } catch (IOException e) { e.printStackTrace(); } } else { status = PluginResult.Status.INVALID_ACTION; } return new PluginResult(status, result); }
From source file:at.wada811.imageslider.MainActivity.java
private int getOrientationFromExif(String filePath) { try {// w ww . j a v a 2s . com ExifInterface exifInterface = new ExifInterface(filePath); int orientationAttr = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); LogUtils.d("orientationAttr: " + orientationAttr); switch (orientationAttr) { case ExifInterface.ORIENTATION_NORMAL: return 0; case ExifInterface.ORIENTATION_ROTATE_90: return 90; case ExifInterface.ORIENTATION_ROTATE_180: return 180; case ExifInterface.ORIENTATION_ROTATE_270: return 270; } } catch (IOException e) { e.printStackTrace(); } return 0; }
From source file:com.google.android.gms.samples.vision.face.photo.PhotoViewerActivity.java
public Bitmap grabImage() { this.getContentResolver().notifyChange(photoURI, null); ContentResolver cr = this.getContentResolver(); Bitmap bitmap;/*w w w . j a va2 s. c o m*/ try { bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, photoURI); ExifInterface ei = new ExifInterface(mCurrentPhotoPath); int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: bitmap = rotateImage(bitmap, 90); break; case ExifInterface.ORIENTATION_ROTATE_180: bitmap = rotateImage(bitmap, 180); break; case ExifInterface.ORIENTATION_ROTATE_270: bitmap = rotateImage(bitmap, 270); break; case ExifInterface.ORIENTATION_NORMAL: default: break; } return bitmap; } catch (Exception e) { Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show(); Log.d(TAG, "Failed to load", e); return null; } }