8

我想创建像上面那样的东西,那三个盒子,就像一个相机预览。关于做什么的任何想法或概念?

我尝试获取相机实例并将其放置到三个 camerapreview 对象,但我收到一条错误消息,我猜,这是不允许的。这是我的代码:

  private CameraPreview mPreview;
  private CameraPreview mPreview2;
  private CameraPreview mPreview3;
  private FrameLayout preview;
  private FrameLayout preview2;
  private FrameLayout preview3;

    mCamera=getCameraInstance(); 
    mCamera2=getCameraInstance();
    mCamera3=getCameraInstance();

    mPreview=new CameraPreview(getApplicationContext(), mCamera);
    mPreview2=new CameraPreview(getApplicationContext(), mCamera2);
    mPreview3=new CameraPreview(getApplicationContext(), mCamera3);

    preview=(FrameLayout)findViewById(R.id.camSetA_qr1);
    preview.addView(mPreview);
    preview2=(FrameLayout)findViewById(R.id.camSetA_qr1);
    preview2.addView(mPreview2);
    preview3=(FrameLayout)findViewById(R.id.camSetA_qr1);
    preview3.addView(mPreview3);

和我的getinstance代码

 public static Camera getCameraInstance() {
    Camera c = null;
    try {
        c = Camera.open();
    } catch (Exception e) {
    }
    return c;
 }
4

1 回答 1

3

You can only open a given camera (front or back) once; you cannot open the camera multiple times to produce multiple preview streams. In fact, on most devices, you can't open the front and back cameras simultaneously, since the camera processing pipeline is shared between the two cameras.

To do this, you need to only open the camera once, and then split the output preview data into the three parts that you then display.

If you need to run on Android versions before 3.0 (Honeycomb), then you need to use the preview callbacks. With them, you'll get a byte[] array of YUV data for each frame that you can then crop, convert to RGB, and place in an ImageView or SurfaceView.

On Android 3.0 or later, you can use the setPreviewTexture method to pipe the preview data into an OpenGL texture, which you can then render to multiple quads in a GLSurfaceView or equivalent.

于 2013-02-24T10:31:00.983 回答