[英]Detach Image produced from ImageReader
I trying to create an Android App that using Camera2 API, as part of the functionality I want to develop a module that saving multiple images produced by ImageReader as followed:我试图创建一个使用 Camera2 API 的 Android 应用程序,作为我想开发一个模块来保存 ImageReader 生成的多个图像的功能的一部分,如下所示:
Image image = reader.acquireLatestImage();
图片 image = reader.acquireLatestImage();
I'm getting the followed Exception:我收到以下异常:
IllegalStateException too many images are currently acquired
IllegalStateException 当前获取的图像过多
as mentioned in the documention: https://developer.android.com/reference/android/media/ImageReader#acquireLatestImage()如文档中所述: https://developer.android.com/reference/android/media/ImageReader#acquireLatestImage()
This is because the image returned from 'acquireLatestImage' is still belongs to the ImageReader Queue.这是因为从 'acquireLatestImage' 返回的图像仍然属于 ImageReader 队列。
Is there any way to detach images returning from 'ImageReader'?有没有办法分离从“ImageReader”返回的图像?
Is there a way to copy an image, preferably without to store it on disk, that is a resource consuming operation?有没有办法复制图像,最好不要将其存储在磁盘上,这是一个资源消耗操作?
Thank's谢谢
If this is a YUV_420_888 image, you can copy each of the plane ByteBuffers to keep the data around indefinitely.如果这是 YUV_420_888 图像,您可以复制每个平面 ByteBuffers 以无限期地保留数据。 That is somewhat expensive, of course.
当然,这有点贵。
Unfortunately, there's no way to easily detach the Image from the ImageReader.不幸的是,没有办法轻松地将 Image 从 ImageReader 中分离出来。 The Reader is a circular buffer queue internally, so removing an Image would require the Reader to allocate a new image to replace the one removed, which is somewhat expensive as well.
Reader 在内部是一个循环缓冲区队列,因此删除 Image 需要 Reader 分配一个新图像来替换已删除的图像,这也有点昂贵。
It can be done by using an ImageWriter.queueInputImage , connected to another ImageReader with the same configuration as the original ImageReader.它可以通过使用ImageWriter.queueInputImage来完成,该 ImageWriter.queueInputImage 连接到另一个具有与原始 ImageReader 相同配置的 ImageReader。 When you receive image A from your first ImageReader, and you want to keep it, you can queue it into the ImageWriter, and then get the Image handle again from the second ImageReader.
当您从第一个 ImageReader 接收到图像 A 并且想要保留它时,可以将其排队到 ImageWriter,然后再次从第二个 ImageReader 获取图像句柄。 Still need to set maxImages on the second reader high enough to account for all the Images you want to keep around at once, of course.
当然,仍然需要将第二个阅读器上的 maxImages 设置得足够高,以考虑一次要保留的所有图像。 That's fairly cumbersome, of course, and if you're doing this continually you'll cause a lot of memory reallocation and copies may be just as expensive (and simpler in many ways).
当然,这相当麻烦,如果您不断这样做,您将导致大量 memory 重新分配,并且副本可能同样昂贵(并且在许多方面更简单)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.