相机2使用。当我调用 closeCamera 时,显示最后看到的帧而不是黑屏
camera2 used. When I call closeCamera, last seen frame is displayed instead of black screen
我实现了 3 种状态的相机:自拍(正面)、背面和关闭。
除 'off' 状态外,一切正常。
我正在使用 camera2,它显示在 TextureView 上:
<TextureView
android:id="@+id/texture_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Expected: When 'off' state is chosen, I would like to close the camera and show black screen .
实际:在'off'状态下,显示相机最后看到的帧。
closeCamera 方法:
private void closeCamera() {
try {
mCameraOpenCloseLock.acquire();
closePreviewSession();
if (null != mCameraDevice) {
mCameraDevice.close();
mCameraDevice = null;
}
if (null != mMediaRecorder) {
mMediaRecorder.release();
mMediaRecorder = null;
}
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while trying to lock camera closing.");
} finally {
mCameraOpenCloseLock.release();
}
}
private void closePreviewSession() {
if (mPreviewSession != null) {
mPreviewSession.close();
mPreviewSession = null;
}
}
知道如何导致 'closeCamera' 显示黑屏吗?
最简单的选择可能是在关闭相机时用单独的黑色视图覆盖 TextureView。
或者在不使用时隐藏 TextureView。
我实现了 3 种状态的相机:自拍(正面)、背面和关闭。
除 'off' 状态外,一切正常。
我正在使用 camera2,它显示在 TextureView 上:
<TextureView
android:id="@+id/texture_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Expected: When 'off' state is chosen, I would like to close the camera and show black screen .
实际:在'off'状态下,显示相机最后看到的帧。
closeCamera 方法:
private void closeCamera() {
try {
mCameraOpenCloseLock.acquire();
closePreviewSession();
if (null != mCameraDevice) {
mCameraDevice.close();
mCameraDevice = null;
}
if (null != mMediaRecorder) {
mMediaRecorder.release();
mMediaRecorder = null;
}
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while trying to lock camera closing.");
} finally {
mCameraOpenCloseLock.release();
}
}
private void closePreviewSession() {
if (mPreviewSession != null) {
mPreviewSession.close();
mPreviewSession = null;
}
}
知道如何导致 'closeCamera' 显示黑屏吗?
最简单的选择可能是在关闭相机时用单独的黑色视图覆盖 TextureView。
或者在不使用时隐藏 TextureView。