我正在使用包含前后摄像头的自定义录像机。当我开始在后置摄像头录制时没问题,当我开始录制前置摄像头时,相机的亮度降低了。
我有相机切换按钮来改变前后摄像头
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;
}
答案 0 :(得分:0)
您应尝试操作相机ISO设置。 因为它可以让相机捕获更多光线,您可以解决您的问题。
Camera camera = Camera.open();
Camera.Parameters params =
camera.getParameters();
params.set("iso", "400");
camera.setParameters(params);
可以有更多的iso设置为100,200,1000,auto等
如果您只想为前凸轮隔离此设置,那么只有在凸轮处于前凸轮状态时才操纵它。
请告诉我这是否为您改变了一切。