如何找到使用 Intent MediaStore.ACTION_IMAGE_CAPTURE 拍摄的照片的方向? [英] How can I find the orientation of a picture taken with Intent MediaStore.ACTION_IMAGE_CAPTURE?
问题描述
当我使用 Android 的相机应用拍照时,它会检测手机的方向并相应地保存照片.因此,如果我拍摄建筑物的照片,屋顶将在顶部,无论我是横向还是纵向握住手机.
When I take a picture with Android's camera app, it detects the phone's orientation and saves the picture accordingly. So if I take a picture of a building, the roof will be on the topside, whether I hold the phone in landscape position or portrait.
但是,当我使用
Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
要获取图片,相机应用程序不会对方向做出反应.如果我垂直握住手机(纵向),生成的图片将旋转,所述建筑物的屋顶位于屏幕左侧.
to get a picture, the camera app doesn't react to the orientation. If I hold the phone vertically (portrait), the resulting picture will be rotated, with said building's roof to the left of the screen.
如何设置 Intent 以便相机将方向考虑在内?
How can I set the intent so that the camera will take the orientation into account?
或者我可以以某种方式推断照片是在哪个方向拍摄的,然后自己旋转它?
Or can I deduce in some way in what orientation the picture was taken and rotate it myself afterwards?
或者还有其他方法吗?
推荐答案
我找到了答案.图片的 Exif 具有方向指示符.以防万一,Exif 可以像这样在 Android 中查看:
I found the answer. The Exif of the image has an indicator of the orientation. Just in case, Exif can be viewed in Android like this:
ExifInterface exif = new ExifInterface("filepath");
exif.getAttribute(ExifInterface.TAG_ORIENTATION);
这篇关于如何找到使用 Intent MediaStore.ACTION_IMAGE_CAPTURE 拍摄的照片的方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!