2017-08-25 67 views
0

我想顯示在mCameraView什麼Android攝像頭片:如何從打開的hardware.camera2相機渲染視圖?

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    mCameraView = (SurfaceView) findViewById(R.id.camera_view); 

    openCamera(); 
} 

下面的代碼打開相機:

void openCamera() { 
    CameraManager manager = (CameraManager) this.getSystemService(
          Context.CAMERA_SERVICE); 
    try { 
     String cameraId = manager.getCameraIdList()[0]; 
     manager.openCamera(cameraId, new StateCallback() { 
      .... // Other override methods 

      @Override 
      public void onOpened(CameraDevice camera) { 
       // What to type here??? 
      } 

     }, new Handler(cameraThread)); 

    } catch (SecurityException | CameraAccessException exception) { 
     throw new RuntimeException(exception); 
    } 
} 

如何把什麼CameraDevice顯示到mCameraView

回答