use of android.media.ExifInterface in project AndroidPuzzleGame by dragosholban.
the class PuzzleActivity method setPicFromPath.
private void setPicFromPath(String mCurrentPhotoPath, ImageView imageView) {
// Get the dimensions of the View
int targetW = imageView.getWidth();
int targetH = imageView.getHeight();
// Get the dimensions of the bitmap
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
// Determine how much to scale down the image
int scaleFactor = Math.min(photoW / targetW, photoH / targetH);
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
Bitmap rotatedBitmap = bitmap;
// rotate bitmap if needed
try {
ExifInterface ei = new ExifInterface(mCurrentPhotoPath);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotatedBitmap = rotateImage(bitmap, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotatedBitmap = rotateImage(bitmap, 180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotatedBitmap = rotateImage(bitmap, 270);
break;
}
} catch (IOException e) {
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
imageView.setImageBitmap(rotatedBitmap);
}
use of android.media.ExifInterface in project XUtil by xuexiangjys.
the class ImageUtils method getRotateDegree.
/**
* 获取图片旋转角度
* <p>返回 -1 表示异常</p>
*
* @param filePath 文件路径
* @return 旋转角度
*/
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;
}
}
use of android.media.ExifInterface in project edx-app-android by edx.
the class SubsamplingScaleImageView method getExifOrientation.
/**
* Helper method for load tasks. Examines the EXIF info on the image file to determine the orientation.
* This will only work for external files, not assets, resources or other URIs.
*/
private int getExifOrientation(String sourceUri) {
int exifOrientation = ORIENTATION_0;
if (sourceUri.startsWith(ContentResolver.SCHEME_CONTENT)) {
try {
final String[] columns = { MediaStore.Images.Media.ORIENTATION };
final Cursor cursor = getContext().getContentResolver().query(Uri.parse(sourceUri), columns, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
int orientation = cursor.getInt(0);
if (VALID_ORIENTATIONS.contains(orientation) && orientation != ORIENTATION_USE_EXIF) {
exifOrientation = orientation;
} else {
Log.w(TAG, "Unsupported orientation: " + orientation);
}
}
cursor.close();
}
} catch (Exception e) {
Log.w(TAG, "Could not get orientation of image from media store");
}
} else if (sourceUri.startsWith(ImageSource.FILE_SCHEME) && !sourceUri.startsWith(ImageSource.ASSET_SCHEME)) {
try {
ExifInterface exifInterface = new ExifInterface(sourceUri.substring(ImageSource.FILE_SCHEME.length() - 1));
int orientationAttr = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
if (orientationAttr == ExifInterface.ORIENTATION_NORMAL || orientationAttr == ExifInterface.ORIENTATION_UNDEFINED) {
exifOrientation = ORIENTATION_0;
} else if (orientationAttr == ExifInterface.ORIENTATION_ROTATE_90) {
exifOrientation = ORIENTATION_90;
} else if (orientationAttr == ExifInterface.ORIENTATION_ROTATE_180) {
exifOrientation = ORIENTATION_180;
} else if (orientationAttr == ExifInterface.ORIENTATION_ROTATE_270) {
exifOrientation = ORIENTATION_270;
} else {
Log.w(TAG, "Unsupported EXIF orientation: " + orientationAttr);
}
} catch (Exception e) {
Log.w(TAG, "Could not get EXIF orientation of image");
}
}
return exifOrientation;
}
use of android.media.ExifInterface in project matrix-android-sdk by matrix-org.
the class ImageUtils method getOrientationForBitmap.
/**
* Gets the {@link ExifInterface} value for the orientation for this local bitmap Uri.
*
* @param context Application context for the content resolver.
* @param uri The URI to find the orientation for. Must be local.
* @return The orientation value, which may be {@link ExifInterface#ORIENTATION_UNDEFINED}.
*/
public static int getOrientationForBitmap(Context context, Uri uri) {
int orientation = ExifInterface.ORIENTATION_UNDEFINED;
if (uri == null) {
return orientation;
}
if (TextUtils.equals(uri.getScheme(), "content")) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, proj, null, null, null);
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
int idxData = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
String path = cursor.getString(idxData);
if (TextUtils.isEmpty(path)) {
Log.w(LOG_TAG, "Cannot find path in media db for uri " + uri);
return orientation;
}
ExifInterface exif = new ExifInterface(path);
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
}
} catch (Exception e) {
// eg SecurityException from com.google.android.apps.photos.content.GooglePhotosImageProvider URIs
// eg IOException from trying to parse the returned path as a file when it is an http uri.
Log.e(LOG_TAG, "Cannot get orientation for bitmap: " + e.getMessage());
} finally {
if (cursor != null) {
cursor.close();
}
}
} else if (TextUtils.equals(uri.getScheme(), "file")) {
try {
ExifInterface exif = new ExifInterface(uri.getPath());
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
} catch (Exception e) {
Log.e(LOG_TAG, "Cannot get EXIF for file uri " + uri + " because " + e.getMessage());
}
}
return orientation;
}
use of android.media.ExifInterface in project iNaturalistAndroid by inaturalist.
the class ImageUtils method getImageOrientation.
public static int getImageOrientation(String imgFilePath) {
ExifInterface exif = null;
try {
exif = new ExifInterface(imgFilePath);
int degrees = exifOrientationToDegrees(exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL));
return degrees;
} catch (Exception e) {
e.printStackTrace();
// No orientation
return 0;
}
}
Aggregations