public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
textView.setText("获取到的信息");
ExifInterface exif = null;
try {
exif = new ExifInterface(Environment.getExternalStorageDirectory().getPath() + "/pic.jpg");
} catch (IOException e) {
e.printStackTrace();
}
if (null == exif) {
textView.append("\n" + "神马都没有");
} else {
textView.append(getPicInformation(exif));
}
setContentView(textView);
}
public static String getPicInformation(ExifInterface exif) {
StringBuilder sBuilder = new StringBuilder();
sBuilder.append("\n光圈:" + exif.getAttribute(ExifInterface.TAG_APERTURE));//2.0
sBuilder.append("\n拍摄日期:" + exif.getAttribute(ExifInterface.TAG_DATETIME));//2016:05:15 21:34:21
sBuilder.append("\n曝光时间:" + exif.getAttribute(ExifInterface.TAG_EXPOSURE_TIME));// 0.030
sBuilder.append("\n是否有闪光灯:" + exif.getAttribute(ExifInterface.TAG_FLASH));// 0
sBuilder.append("\n焦距: " + exif.getAttribute(ExifInterface.TAG_FOCAL_LENGTH));//4620/1000
sBuilder.append("\n海拔: " + exif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE));//0/100
sBuilder.append("\n海拔参数:" + exif.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF));// 1
sBuilder.append("\n时间戳:" + exif.getAttribute(ExifInterface.TAG_GPS_DATESTAMP));// 2016:05:15
sBuilder.append("\n维度: " + exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE));//23/1,5/1,45224761/1000000
sBuilder.append("\n南半球还是北半球:" + exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF));// N
sBuilder.append("\n经度: " + exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE));//113/1,19/1,23122558/1000000
sBuilder.append("\n东区还是西区:" + exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF));// E
sBuilder.append("\n高: " + exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH));//5152
sBuilder.append("\n宽: " + exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH));//3888
sBuilder.append("\n感光度: " + exif.getAttribute(ExifInterface.TAG_ISO));//200
sBuilder.append("\n生产厂家:" + exif.getAttribute(ExifInterface.TAG_MAKE));// HUAWEI
sBuilder.append("\n设备型号: " + exif.getAttribute(ExifInterface.TAG_MODEL));//PLK-AL10
sBuilder.append("\n旋转角度: " + exif.getAttribute(ExifInterface.TAG_ORIENTATION));//1
sBuilder.append("\n白平衡:" + exif.getAttribute(ExifInterface.TAG_WHITE_BALANCE));// 0
sBuilder.append("\n旋转角度为:" + readPictureDegree(Environment.getExternalStorageDirectory().getPath() + "/pic.jpg") + "°");
return sBuilder.toString();
}
/**获取图片的旋转角度 */
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;
}
} catch (IOException e) {
e.printStackTrace();
}
return degree;
}
}