gpt4 book ai didi

Android Camera2 图片在图库中出现旋转

转载 作者:太空狗 更新时间:2023-10-29 14:42:57 24 4
gpt4 key购买 nike

我制作了一个使用 Google Camera2 sample 拍照(人像、风景或自拍)的应用程序.一切正常,我可以拍照,保存照片等等。

但是当我打开手机 (Samsung S7) 的图库时,所有自拍和人像图片都旋转了 90 度。风景照还是不错的。我看过很多关于如何以正确方向阅读图像的帖子,但是如何正确保存它们呢?

我的应用程序中有我自己的图库,图片已正确加载(使用 Glide),没有任何特殊的旋转修复,所以我不确定我做错了什么,最重要的是,我该如何解决这个问题?

最佳答案

您使用的是 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;
}

输入设备方向来自传感器 API。

关于Android Camera2 图片在图库中出现旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44863661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com