您是否在您的静止捕捉请求中使用了JPEG_ORIENTATION控件?如果没有,那可能是问题 - 该控件告诉相机设备如何将最终的JPEG图像旋转为正面朝上。
因此,您需要更新该控件中的值以描述图像传感器当前相对于世界的排列方式。
要做到这一点计算,你需要从加速度计输入(它告诉你哪个方向是向下),然后是一些基本的数学 - 从上面的链接复制此:
private int getJpegOrientation(CameraCharacteristics c, int deviceOrientation) {
if (deviceOrientation == android.view.OrientationEventListener.ORIENTATION_UNKNOWN) return 0;
int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);
// Round device orientation to a multiple of 90
deviceOrientation = (deviceOrientation + 45)/90 * 90;
// Reverse device orientation for front-facing cameras
boolean facingFront = c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT;
if (facingFront) deviceOrientation = -deviceOrientation;
// Calculate desired JPEG orientation relative to camera orientation to make
// the image upright relative to the device orientation
int jpegOrientation = (sensorOrientation + deviceOrientation + 360) % 360;
return jpegOrientation;
}
其中输入deviceOrientation来自传感器API。
将其中一个图像从设备上拉出来,并使用'exiftool'或其他东西进行检查。或者,将一些使用'ExifInterface'的'com.android.support:exifinterface'版本的代码一起扔掉。无论哪种情况,您都在查看是否存在具有期望值的定位EXIF标签。如果存在,那么问题不在于保存图像,而是您正在使用的图库应用程序中的错误。欢迎尝试在保存之前手动旋转图像(并删除方向标记),但可能没有足够的堆空间来执行此操作。 – CommonsWare
如果OTOH,该标签丢失,那么在保存图像的方式上可能存在错误,这需要[mcve]。 – CommonsWare
我在其中一个selfies上运行exiftool,并获得了一个方向标签:“旋转270 CW”。所以我猜画廊有问题吗? – barouf