如何创建使用Android的一个摄像头的多镜头或preVIEW摄像头、镜头、Android、preVIEW

2023-09-05 03:01:17 作者:曾经一身傲气

我想创造的东西像上面那三盒,就会像一个摄像头preVIEW。怎样做任何想法或概念?

我试图进入相机的实例,并将其放置到三个摄像头preVIEW的对象,但我得到一个错误信息,我想,它是不允许的。这里是我的code:

 专用摄像头preVIEW米preVIEW;
  私人相机preVIEW米preview2;
  私人相机preVIEW米preview3;
  私人的FrameLayout preVIEW;
  私人的FrameLayout preview2;
  私人的FrameLayout preview3;

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

    米preVIEW =新相机preVIEW(getApplicationContext(),mCamera);
    米preview2 =新相机preVIEW(getApplicationContext(),mCamera2);
    米preview3 =新相机preVIEW(getApplicationContext(),mCamera3);

    preVIEW =(的FrameLayout)findViewById(R.id.camSetA_qr1);
    preview.addView(M preVIEW);
    preview2 =(的FrameLayout)findViewById(R.id.camSetA_qr1);
    preview2.addView(M preview2);
    preview3 =(的FrameLayout)findViewById(R.id.camSetA_qr1);
    preview3.addView(M preview3);
 

和我的getInstance code

 公共静态相机getCameraInstance(){
    相机C = NULL;
    尝试 {
        C = Camera.open();
    }赶上(例外五){
    }
    返回℃;
 }
 

解决方案 android的一个app代码怎么写,如何写一个适用于Android的应用

您只能打开一个给定的摄像头(正面或背面)一次;无法打开相机多次产生多个preVIEW流。事实上,在大多数设备,则不能同时打开的正面和背面摄像机,由于照相机处理管道是两个相机之间共享。

要做到这一点,你只需要打开摄像头后,然后将输出preVIEW数据拆分成三部分,你再显示。

如果您需要在之前3.0(蜂窝)在Android版本上运行,那么你就需要使用 preVIEW回调。有了他们,你会得到的YUV数据的byte []数组的每一帧,然后可以裁剪,转换为RGB,并将其放置在一个ImageView的或SurfaceView。

在Android 3.0或更高版本,可以使用设置previewTexture 的方法来管preVIEW数据转换成一个OpenGL纹理,然后你就可以呈现在一个GLSurfaceView或相当多的四边形。

I wanted to create something like above, that three box, will be like a camera preview. Any idea or concept on what to do?

I tried getting instance of the camera and place it to three camerapreview objects, but i'm getting an error message, i guess, it's not allowed. here is my code:

  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);

and my getinstance code

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

解决方案

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.