如何在彼此之间显示两个表面?

时间:2022-06-28 01:22:02

I have a 3D cube and I open the camera preview, and I want to see this rotating cube displayed over the camera.

我有一个3D立方体,我打开相机预览,我想看到这个旋转立方体显示在相机上。

What I attempted is, inside the SurfaceChanged method of the class that implements surfaceHolder.callback, I call camera.setPreviewCallback(new PreviewCallback(){ } as follows:

我尝试的是,在实现surfaceHolder.callback的类的SurfaceChanged方法中,我调用camera.setPreviewCallback(new PreviewCallback(){},如下所示:

public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {
.......
.......
.......
camera.setPreviewCallback(new PreviewCallback() {
        @Override
        public void onPreviewFrame(byte[] data, Camera camera) {
            // TODO Auto-generated method stub
            glSurface.setRenderer( new MyRender());
            setContentView(glSurface);
        }
    });

This code results in, displaying the camera preview for a few seconds until the surface is changed, then, the camera preview disappears and the 3D cube appears on a black background.

此代码生成,显示相机预览几秒钟直到曲面更改,然后,相机预览消失,3D立方体出现在黑色背景上。

Is there anyway to show both surfaces?

无论如何要显示两个表面?

2 个解决方案

#1


1  

As far as I recall, you have to set the CameraPreview ontop of the GlView. Thats not intuitive, but should work. here is a link that may help you: http://digitalbreed.com/2009/android-render-opengl-on-top-of-camera-preview

据我所知,你必须在GlView的顶部设置CameraPreview。这不直观,但应该工作。这是一个可以帮助您的链接:http://digitalbreed.com/2009/android-render-opengl-on-top-of-camera-preview

#2


0  

You can do your own offscreen compositing, then draw the result into a single SurfaceView. See this sample code for details.

您可以进行自己的屏幕外合成,然后将结果绘制到单个SurfaceView中。有关详细信息,请参阅此示例代

#1


1  

As far as I recall, you have to set the CameraPreview ontop of the GlView. Thats not intuitive, but should work. here is a link that may help you: http://digitalbreed.com/2009/android-render-opengl-on-top-of-camera-preview

据我所知,你必须在GlView的顶部设置CameraPreview。这不直观,但应该工作。这是一个可以帮助您的链接:http://digitalbreed.com/2009/android-render-opengl-on-top-of-camera-preview

#2


0  

You can do your own offscreen compositing, then draw the result into a single SurfaceView. See this sample code for details.

您可以进行自己的屏幕外合成,然后将结果绘制到单个SurfaceView中。有关详细信息,请参阅此示例代