如何判断横图还是竖图
横图的标准:宽度大于高度。
竖图的标准:高度大于宽度。
直觉思维
我获取一个图片的分辨率,如果这个图是竖图,肯定是高度大于宽度的,如果这个图是横图,肯定是宽度大于高度的。
意外出现
测试了一个 oppo 手机,嗯,是正常的。
测试到小米9,结果横图竖图都是一样的分辨率,我当时就......想到再获取下角度试试。
结果
发现有迹可循,就在90度和270度的时候,自动调换一下宽度和高度换算一下吧。
附:
如何获取分辨率
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getAbsolutePath(), opts);
int width = ops.outWidth;
int height = ops.outHeight;
如何获取旋转角度
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;
}