在项目过程中,需要计算本地图片或者网络图片原来的旋转角度。这部分代码是从Glide的DownSampler类的,这里做一下记录。
Glide的类ImageHeaderParser中负责解析Image的头部信息,Glide分成两种情况:
- DefaultImageHeaderParser 默认的头部,是Glide自定义的头部解析器
- ExifInterfaceImageHeaderParser 利用了ExifInterface
一种是Android 7.0以上利用ExifInterface计算,另外一种低版本的Glide自定义的来解析头部信息获取旋转角度
我只是用了ExifInterfaceImageHeaderParser 的部分代码来获取角度,为了兼容低版本,还需要引入
implementation ‘com.android.support:exifinterface:28.0.0’
public class DownSampler {
private static final int MARK_POSITION = 10 * 1024 * 1024;
public static Size getDimensions(BufferedInputStream is, BitmapFactory.Options options) {
options.inJustDecodeBounds = true;
decodeStream(is, options);
options.inJustDecodeBounds = false;
return new Size(options.outWidth, options.outHeight);
}
public static boolea