在一些设备上,CaptureSession拍摄的照片会旋转到风景中,这没问题。
我的问题是,我会检测图片是否保存在景观中,并将其旋转回来保存。因为现在,结果是用户让一些型号的个人资料图像旋转。
目前,我已经尝试了许多解决方案,包括
getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);它总是返回0。
我在想,如果由于某种原因,JPEG文件中的Exif标签没有设置,但我没有找到任何关于它的东西。
到目前为止,我的解决方案中效果最好的是这个。它只检查高度和宽度。这并不总是有效的。很多设备都有旋转图片的问题。
public static Bitmap rotate90ifneeded(Bitmap bitmap, int width, int height) {
Bitmap bitmap2 = bitmap;
if(bitmap.getHeight() < bitmap.getWidth()) {
Matrix matrix = new Matrix();
matrix.postRotate(90);
bitmap2 = Bitmap.createBitmap(bitmap , 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
return bitmap2;
}发布于 2015-11-05 18:01:32
使用此方法可确定图像旋转。
public int getCameraPhotoOrientation(Uri imageUri, String imagePath) {
int rotate = 0;
try {
_context.getContentResolver().notifyChange(imageUri, null);
File imageFile = new File(imagePath);
ExifInterface exif = new ExifInterface(
imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
} catch (Exception e) {
}
return rotate;
}如果该方法不返回Zero,则旋转图像。
int degree=getCameraPhotoOrientation(Uri.fromFile(tempFile), fPath);
if (degree!= 0) {
bitmap = tools.rotateOrientationCall(bitmap, degree);
}旋转您的位图。
public Bitmap rotateOrientationCall(Bitmap src, float degree) {
Matrix matrix = new Matrix();
matrix.postRotate(degree);
return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
}https://stackoverflow.com/questions/33541481
复制相似问题