每当我尝试在我的自定义相机中捕捉照片时,我都无法检测到它的方向。捕获的图像存储在SD卡中,然后我检索预览我使用ExifInterface进行方向,但图像的方向总是在ExifInterface.ORIENTATION_NORMAL模式下,无论我捕获它的横向或纵向。我已经尝试了所有的东西,但没有找到任何解决方案。
Matrix mat = new Matrix();
ExifInterface exif = new ExifInterface(path);
String orientstring = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
int orientation = orientstring != null ? Integer.parseInt(orientstring) : ExifInterface.ORIENTATION_NORMAL;
int rotateangle = 0;
if (orientation == ExifInterface.ORIENTATION_NORMAL){
rotateangle = 90;
}
if(orientation == ExifInterface.ORIENTATION_ROTATE_90)
rotateangle = 90;
if(orientation == ExifInterface.ORIENTATION_ROTATE_180)
rotateangle = 180;
if(orientation == ExifInterface.ORIENTATION_ROTATE_270)
rotateangle = 270;
mat.setRotate(rotateangle, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2);
File f = new File(path);
Bitmap bmpPic = BitmapFactory.decodeStream(new FileInputStream(f), null, null);
int widthBmp=bmpPic.getWidth();
int heightBmp=bmpPic.getHeight();
if (heightBmp < widthBmp){
bitmap = Bitmap.createBitmap(bmpPic, 0, 0, bmpPic.getWidth(), bmpPic.getHeight(), mat, true);
}
return bitmap;
提前感谢您的帮助。