use of android.media.ExifInterface in project BaseProject by fly803.
the class AppImageMgr method readPictureDegree.
/**
* 判断图片旋转情况
*
* @param path
* @return
*/
public static int readPictureDegree(String path) {
int degree = 0;
try {
final ExifInterface exifInterface = new ExifInterface(path);
final 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;
}
use of android.media.ExifInterface in project BaseProject by fly803.
the class BitmapUtils method getImageDegree.
/**
* 读取图片属性:图片被旋转的角度
*
* @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;
}
use of android.media.ExifInterface in project OpenCamera by ageback.
the class ImageSaver method setExifFromData.
/**
* As setExifFromFile, but can read the Exif tags directly from the jpeg data rather than a file.
*/
@RequiresApi(api = Build.VERSION_CODES.N)
private void setExifFromData(final Request request, byte[] data, File to_file) throws IOException {
if (MyDebug.LOG) {
Log.d(TAG, "setExifFromData");
Log.d(TAG, "to_file: " + to_file);
}
InputStream inputStream = null;
try {
inputStream = new ByteArrayInputStream(data);
ExifInterface exif = new ExifInterface(inputStream);
ExifInterface exif_new = new ExifInterface(to_file.getAbsolutePath());
setExif(request, exif, exif_new);
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
use of android.media.ExifInterface in project OpenCamera by ageback.
the class ImageSaver method updateExif.
/**
* Makes various modifications to the saved image file, according to the preferences in request.
*/
private void updateExif(Request request, File picFile) throws IOException {
if (MyDebug.LOG)
Log.d(TAG, "updateExif: " + picFile);
if (request.store_geo_direction || hasCustomExif(request.custom_tag_artist, request.custom_tag_copyright)) {
if (MyDebug.LOG)
Log.d(TAG, "add additional exif info");
try {
ExifInterface exif = new ExifInterface(picFile.getAbsolutePath());
modifyExif(exif, request.type == Request.Type.JPEG, request.using_camera2, request.current_date, request.store_location, request.store_geo_direction, request.geo_direction, request.custom_tag_artist, request.custom_tag_copyright);
exif.saveAttributes();
} catch (NoClassDefFoundError exception) {
// have had Google Play crashes from new ExifInterface() elsewhere for Galaxy Ace4 (vivalto3g), Galaxy S Duos3 (vivalto3gvn), so also catch here just in case
if (MyDebug.LOG)
Log.e(TAG, "exif orientation NoClassDefFoundError");
exception.printStackTrace();
}
} else if (needGPSTimestampHack(request.type == Request.Type.JPEG, request.using_camera2, request.store_location)) {
if (MyDebug.LOG)
Log.d(TAG, "remove GPS timestamp hack");
try {
ExifInterface exif = new ExifInterface(picFile.getAbsolutePath());
fixGPSTimestamp(exif, request.current_date);
exif.saveAttributes();
} catch (NoClassDefFoundError exception) {
// have had Google Play crashes from new ExifInterface() elsewhere for Galaxy Ace4 (vivalto3g), Galaxy S Duos3 (vivalto3gvn), so also catch here just in case
if (MyDebug.LOG)
Log.e(TAG, "exif orientation NoClassDefFoundError");
exception.printStackTrace();
}
} else {
if (MyDebug.LOG)
Log.d(TAG, "no exif data to update for: " + picFile);
}
}
use of android.media.ExifInterface in project GomoTest by suReZj.
the class BitmapUtils method getOrientation.
// public static Bitmap loadImageByPath(final String imagePath, int reqWidth,
// int reqHeight) {
// File file = new File(imagePath);
// if (file.length() < MAX_SZIE) {
// return getSampledBitmap(imagePath, reqWidth, reqHeight);
// } else {// 压缩图片
// return getImageCompress(imagePath);
// }
// }
public static int getOrientation(final String imagePath) {
int rotate = 0;
try {
File imageFile = new File(imagePath);
ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
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;
}
} catch (Exception e) {
e.printStackTrace();
}
return rotate;
}
Aggregations