在cameraPreview上显示3D旋转物体?

时间:2012-03-31 12:00:49

标签: android android-camera surfaceview glsurfaceview

我创建了3D对象,我也在显示相机预览。 CameraPreview是

显示在XML文件中定义的SurfaceView上,3D对象显示在

在XML文件中定义的framelayout。我想在

上显示旋转的3D对象

CameraPreview,但是当我运行App时,CameraPreview正在显示少数

秒后,活动显示独立于

的3D旋转对象

cameraPreview,我的意思是,旋转的3D对象不会显示在Camerapreview

表面。有没有办法解决这个错误?

非常感谢你的帮助。

代码

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mpinfo);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);

        surfaceView = (SurfaceView)findViewById(R.id.camerapreview);   
        surfaceView.setZOrderOnTop(true);
        surfaceHolder = surfaceView.getHolder();
        surfaceHolder.setFormat(PixelFormat.TRANSPARENT);           
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub
        if(previewing){
            camera.stopPreview();
            previewing = false;
    }

        if (camera != null){
        try {
              camera.setPreviewDisplay(surfaceHolder);
              camera.startPreview();
              previewing = true;
        } catch (IOException e) {
          // TODO Auto-generated catch block
              e.printStackTrace();
        }
        }
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub

        camera = android.hardware.Camera.open();    
        //Create an Instance with this Activity
        glSurface = new GLSurfaceView(this);

        //Set our own Renderer
        glSurface.setRenderer(new Lesson05());

        //Set the GLSurface as View to this Activity

        fl01 = (FrameLayout) findViewById(R.id.fl01);

        //setContentView(glSurface);
        //fl01.addView(cameraSurface);

        fl01.addView(glSurface);
    }

xml文件

<FrameLayout 
                android:id="@+id/fl01"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
            </FrameLayout>
            <SurfaceView
                android:id="@+id/camerapreview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"/>

0 个答案:

没有答案