setPreviewTexture() API 的等效 Camera2 API 是什么? [英] What is the equivalent Camera2 API for setPreviewTexture() API?

查看:177
本文介绍了setPreviewTexture() API 的等效 Camera2 API 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试获取GL Texture并从中生成SurfaceTexture,并将其提供给Camera目标端,以便我可以在着色器程序中使用Texture进行渲染.

I have been trying to get the GL Texture and generate a SurfaceTexture from it, and provide to the Camera destination end, so that i can use Texture in the shader program to render.

在 Camera2 API 之前,我可以看到下面的 API.https://developer.android.com/reference/android/hardware/Camera.html#setPreviewTexture(android.graphics.SurfaceTexture)

Before Camera2 API, i could see the API below. https://developer.android.com/reference/android/hardware/Camera.html#setPreviewTexture(android.graphics.SurfaceTexture)

我一直在寻找 Camera2 API 的等效 API.有人可以提供提示吗?或者任何替代方案,例如使用 TextureView 的 setSurfaceTexture(SurfaceTexture openGLMappedSurfaceTexture) ?

I have been hunting the equivalent API for Camera2 API. Could someone provide the hint? Or any alternative say something like, using setSurfaceTexture(SurfaceTexture openGLMappedSurfaceTexture) of TextureView?

推荐答案

试试这个:

            SurfaceTexture texture = mTextureView.getSurfaceTexture();
            assert texture != null;

            // We configure the size of default buffer to be the size of camera preview we want.
            texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());

            // This is the output Surface we need to start preview.
            Surface surface = new Surface(texture);

            // We set up a CaptureRequest.Builder with the output Surface.
            mPreviewRequestBuilder
                    = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
            mPreviewRequestBuilder.addTarget(surface);

请参考此示例以更好地理解:

Please refer this sample for a better understanding:

https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java

这篇关于setPreviewTexture() API 的等效 Camera2 API 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆