简体   繁体   English

分离从 ImageReader 生成的图像

[英]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.

相关问题 如何为从ImageReader Camera2接收的图像映射CameraResult的getFrameNumber - How to map getFrameNumber of CameraResult for Image receive from ImageReader Camera2 使用OpenCV从Android Camera2将YUV转换为RGB ImageReader时出现问题,输出图像为灰度 - Problem converting YUV to RGB ImageReader from android Camera2 using OpenCV, output image is in grayscale Android的ImageReader无法读取任何图像 - ImageReader Android can't read any image Android Camera2 ImageReader图像格式YUV - Android Camera2 ImageReader Image Format YUV 如何从ImageReader android获取InputStream - How to get InputStream from ImageReader android 使用ImageReader保存时,Android camera2预览图像无序 - Android camera2 preview image disorder when saved using ImageReader 从 RecyclerView 中分离 ItemTouchHelper - Detach ItemTouchHelper from RecyclerView Kotlin 和相机 2 中的 ImageReader - 从相机读取器表面保存.jpg 文件 - ImageReader in Kotlin & Camera 2 - saving .jpg file from a camera reader surface 从视频读取图像时,ImageReader读取了错误的数据? - Got wrong data by ImageReader when reading from a video? 解释来自格式为 ImageFormat.Private 的 ImageReader 的数据 - Interpreting data from an ImageReader with format ImageFormat.Private
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM