gpt4 book ai didi

android - 我如何知道图像是否在缓冲区中旋转?

转载 作者:行者123 更新时间:2023-12-02 13:43:50 33 4
gpt4 key购买 nike

我目前正在使用 OnImageCaptured 回调来获取我的图像,而不是将其保存到设备。当图像来自 ImageProxy 时,我无法理解何时需要旋转图像。

我使用以下方法将数据从 ImageProxy 转换为 BitMap:

...
val buffer: ByteBuffer = imageProxy.planes[0].buffer // Only first plane because of JPEG format.
val bytes = ByteArray(buffer.remaining())
buffer.get(bytes)
return BitmapFactory.decodeByteArray(bytes, 0, bytes.size)

生成的位图有时会旋转,有时不会旋转,具体取决于拍摄图片的设备。 ImageProxy.getImageInfo().getRotationDegrees() 返回正确的旋转,但我不知道什么时候需要应用它,因为它有时应用在位图中,有时不应用。

ImageCapture.OnCapturedImageListener documentation还说:

The image is provided as captured by the underlying ImageReader without rotation applied. rotationDegrees describes the magnitude of clockwise rotation, which if applied to the image will make it match the currently configured target rotation.

这让我认为我得到的位图不正确,因为有时它应用了旋转。我在这里遗漏了什么吗?

最佳答案

好吧,事实证明唯一必要的信息是 Exif 元数据。 rotationDegrees 包含图像应处于的最终方向,从基本方向开始,但 Exif 元数据仅显示我为获得最终结果而必须进行的旋转。所以根据 TAG_ORIENTATION 旋转解决了这个问题。

  • 更新:这是 CameraX 库本身的问题。它已在 1.0.0-beta02 中修复,因此现在 exif 元数据和 rotationDegrees 包含相同的信息。

关于android - 我如何知道图像是否在缓冲区中旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60956404/

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