创建camera2会话后如何添加SurfaceView的多个表面

编程入门 行业动态 更新时间:2024-10-26 07:29:07
本文介绍了创建camera2会话后如何添加SurfaceView的多个表面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个应用程序使用 ImageReader 连续保存相机图像.

I have an app saving camera images continuously by using ImageReader.

现在我有必要动态添加多个 SurfaceView,以便在创建相机会话后显示不同大小的预览.

Now I have a requisite need to add multiple SurfaceView dynamically for showing different size of preview after camera session created.

因为 ImageReader 的表面是在 session 创建之前添加的:

Because the surface of ImageReader was added before session created like this:

mBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)
mBuilder!!.addTarget(mImageReader!!.surface)

val surfaces = ArrayList<Surface>()
surfaces.add(mImageReader!!.surface)
mCameraDevice!!.createCaptureSession(surfaces, mSessionCallback, mBackgroundHandler)

我的新 SurfaceView 将在 createCaptureSession 之后创建.

And my new SurfaceView will be create after createCaptureSession.

那么我应该如何为设备添加另一个预览表面以接收来自 camera2 的接收器数据?

So how should I add another preview surface to device for receiver data from camera2?

推荐答案

对于不同的输出分辨率,camera2 无法直接做到这一点.如果您需要更改输出的分辨率,则必须使用所需的新输出创建新的捕获会话.

This is not possible with the camera2 directly, for different output resolutions. If you need to change the resolution of an output, you have to create a new capture session with the new outputs you want.

如果您想要多个相同大小的 SurfaceView,您可以使用在 API 级别 26 及更高版本中添加的 Surface 共享 API,在 OutputConfiguration (https://developer.android/reference/android/hardware/camera2/params/OutputConfiguration).

If you want multiple SurfaceViews of the same size, you can use the surface sharing APIs added in API level 26 and later in OutputConfiguration (https://developer.android/reference/android/hardware/camera2/params/OutputConfiguration).

如果这还不够,另一种选择是将相机连接到具有您可能需要的最大 SurfaceView 分辨率的 SurfaceTexture,然后通过 OpenGL 渲染较低分辨率的输出,为您要绘制的每个新 SurfaceView 创建 EGL 窗口到.这是设置 EGL 上下文和渲染所需的大量代码,但应该相当有效.

If that's not sufficient, the other option is to connect the camera to a SurfaceTexture with the maximum SurfaceView resolution you might want, and then render lower resolution outputs from that via OpenGL, creating EGL windows for each new SurfaceView you want to draw to. That's a lot of code needed to set up the EGL context and rendering, but should be fairly efficient.

这篇关于创建camera2会话后如何添加SurfaceView的多个表面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 03:38:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034344.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   表面   SurfaceView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!