切换摄像头
程序员文章站
2022-07-01 15:32:18
...
/**
* 切换前后摄像头
*/
@SuppressWarnings("deprecation")
public void toggleCamera(){
int cameraCount = 0;
CameraInfo cameraInfo = new CameraInfo();
cameraCount = Camera.getNumberOfCameras();// 得到摄像头的个数
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraType == BACK_CAMERA) {
//切换成前置
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
//释放资源
freeCameraResource();
try {
mCamera = Camera.open(camIdx);
cameraType = FRONT_CAMERA;
if (mCamera == null)
return;
setCameraParams();
return;
} catch (RuntimeException e) {
e.printStackTrace();
freeCameraResource();
}
}
}else{
//切换成后置
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
//释放资源
freeCameraResource();
try {
mCamera = Camera.open(camIdx);
cameraType = BACK_CAMERA;
if (mCamera == null)
return;
setCameraParams();
return;
} catch (RuntimeException e) {
e.printStackTrace();
freeCameraResource();
}
}
}
}
}
转载于:https://www.jianshu.com/p/d84ed2b1389d
上一篇: 以太坊源码分析之 P2P网络(五、p2p连接控制与消息处理(中))
下一篇: easyAR切换摄像头