场景: 从iPhone相机拍摄照片并将其上传到服务器上并尝试将同一张照片加载到android设备上时,照片旋转了90度。
到目前为止,我发现的是元信息(EXIF数据)在下载图像之前被Android系统忽略。从iPhone上传照片时,该特定照片的EXIF信息是这样的:向6方向旋转90逆时针旋转,但是对于android,该值变为:向0(未定义)
我尝试了几种方法,但是没有用,请让我知道是否有人遇到类似问题或任何解决方案或解决方法,
示例代码段:
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 4;
resultBitmap = decodeStream(inputStream, null, bmOptions);
ExifInterface exif = new ExifInterface(inputStream);
String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL;
int rotationAngle = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90;
else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180;
else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270;
Matrix matrix = new Matrix();
matrix.setRotate(rotationAngle);
Bitmap rotated = Bitmap.createBitmap(resultBitmap,0,0,resultBitmap.getWidth(),resultBitmap.getHeight(),matrix,true);
if(rotated != null){
resultBitmap = rotated;
}
enter code here