我使用CameraView library來顯示取景器並從中捕捉拍攝對象。 我有兩個按鈕,一個用於打開視圖,另一個用於關閉視圖。第二次使用CameraView黑色時
這兩個按鈕點擊會調用下面的方法真假參數:
public void showCameraLayout(boolean show) {
cameraLoading.setVisibility(View.GONE);
cameraClick.setVisibility(View.VISIBLE);
ivGallery.setVisibility(View.VISIBLE);
if (show) {
showKeyboard(false);
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED) {
if (mCameraView != null) {
mCameraView.addCallback(mCallback);
}
ViewGroup.LayoutParams params = cameraLayout.getLayoutParams();
params.height = messagesView.getWidth()/2;
cameraLayout.setLayoutParams(params);
mCameraView.start();
safeToTakePicture = true;
} else if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
Manifest.permission.CAMERA)) {
ConfirmationDialogFragment
.newInstance(R.string.camera_permission_confirmation,
new String[]{Manifest.permission.CAMERA},
REQUEST_CAMERA_PERMISSION,
R.string.camera_permission_not_granted)
.show(getActivity().getSupportFragmentManager(), FRAGMENT_DIALOG);
} else {
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.CAMERA},
REQUEST_CAMERA_PERMISSION);
}
} else {
ViewGroup.LayoutParams params = cameraLayout.getLayoutParams();
params.height = 0;
cameraLayout.setLayoutParams(params);
if (mCameraView != null) mCameraView.stop();
}
}
的問題是,cameraLayout被打開,第一次的時候,我可以看到直播相機。但是當我關閉它並再次打開它時,它會顯示黑屏。 奇怪的是,如果在顯示黑屏時拍攝對齊圖像,我會得到正確的圖像。
在下次開始之前使用第一次釋放相機之後,如:mCamera.release()。 – Kaushal28
@ Kaushal28這不是Camera API,而是通過CameraView庫使用Camera2 API。 –