0

我正在使用包含前置和后置摄像头的自定义录像机。当我开始在后置摄像头录制时没有问题,当我开始在前置摄像头录制时,摄像头的亮度降低。

我有摄像头切换按钮来改变前后摄像头

int currentCameraId;
reverseCamera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCamera.stopPreview();
            mCamera.release();

            if (currentCameraId == Camera.CameraInfo.CAMERA_FACING_BACK) {
                currentCameraId = Camera.CameraInfo.CAMERA_FACING_FRONT;
            } else {
                currentCameraId = Camera.CameraInfo.CAMERA_FACING_BACK;
            }
            mCamera = Camera.open(currentCameraId);

            setCameraDisplayOrientation(UnlVideoActivity.this, currentCameraId, mCamera);
            try {

                mCamera.setPreviewDisplay(mHolder);
            } catch (IOException e) {
                e.printStackTrace();
            }
            mCamera.startPreview();
        }
    });

 public void setCameraDisplayOrientation(Activity activity,
                                        int cameraId, android.hardware.Camera camera) {
    android.hardware.Camera.CameraInfo info =
            new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    params.setRotation(rotation);
    switch (rotation) {
        case Surface.ROTATION_0:
            Toast.makeText(UnlVideoActivity.this, "LAND", Toast.LENGTH_SHORT).show();
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            Toast.makeText(UnlVideoActivity.this, "PORT", Toast.LENGTH_SHORT).show();
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360;  // compensate the mirror
    } else {  // back-facing
        result = (info.orientation - degrees + 360) % 360;
    }
    camera.setDisplayOrientation(result);
    camera.startPreview();
}

通过这种方式,当我开始记录亮度变低时,我会切换前置摄像头。

录制代码

  private boolean prepareMediaRecorder() {
    mCamera = getCameraInstance();

    mediaRecorder = new MediaRecorder();
    mediaRecorder.setOrientationHint(orientationHint);
    mCamera.unlock();
    mediaRecorder.setPreviewDisplay(mHolder.getSurface());
    mediaRecorder.setCamera(mCamera);

    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

    mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
    mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
    mediaRecorder.setMaxFileSize(5000000); // Set max file size 5M

    mediaRecorder.setPreviewDisplay(mCameraSurfaceView.getHolder().getSurface());

    try {
        mediaRecorder.prepare();
    } catch (IllegalStateException e) {
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        releaseMediaRecorder();
        return false;
    }
    return true;

}
4

1 回答 1

0

您应该尝试操作相机 iso 设置因为它会让相机捕捉到更多的光线,你可能会解决你的问题。

    Camera camera = Camera.open();
 Camera.Parameters params =
 camera.getParameters();
 params.set("iso", "400");
 camera.setParameters(params);

可以有更多的 iso 设置,如 100,200,1000,auto 等

如果您只想为前凸轮隔离此设置,那么如果正在运行的凸轮是前凸轮,则只需对其进行操作。

如果这对您有任何改变,请告诉我。

于 2017-02-23T13:29:10.927 回答