图片Android知识Android开发

android图片旋转之ExifInterface

2017-02-18  本文已影响1544人  金馆长说

ExifInterface是什么?

使用

 // 从指定路径下读取图片,并获取其EXIF信息。这里传入需要获取图片的sd卡路径
 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;
    }

常用方法

可以看到,上面大部分方法操作了一个String类型的tag参数,此为Exif的属性,在ExifInterface中定义了一些字符串的静态常量表示这些tag值,常用如下:

//获取参数值
 ExifInterface exifInterface = new ExifInterface(
 7                             "/sdcard/a.jpg");
 8                     String FFNumber = exifInterface
 9                             .getAttribute(ExifInterface.TAG_APERTURE);
10                     String FDateTime = exifInterface
11                             .getAttribute(ExifInterface.TAG_DATETIME);
12                     String FExposureTime = exifInterface
13                             .getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
14                     String FFlash = exifInterface
15                             .getAttribute(ExifInterface.TAG_FLASH);
16                     String FFocalLength = exifInterface
17                             .getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
18                     String FImageLength = exifInterface
19                             .getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
20                     String FImageWidth = exifInterface
21                             .getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
22                     String FISOSpeedRatings = exifInterface
23                             .getAttribute(ExifInterface.TAG_ISO);
24                     String FMake = exifInterface
25                             .getAttribute(ExifInterface.TAG_MAKE);
26                     String FModel = exifInterface
27                             .getAttribute(ExifInterface.TAG_MODEL);
28                     String FOrientation = exifInterface
29                             .getAttribute(ExifInterface.TAG_ORIENTATION);
30                     String FWhiteBalance = exifInterface
31                             .getAttribute(ExifInterface.TAG_WHITE_BALANCE);
上一篇下一篇

猜你喜欢

热点阅读