• Camera打开前置摄像头或后置摄像头


        private int FindFrontCamera(){  
            int cameraCount = 0;  
            Camera.CameraInfo cameraInfo = new Camera.CameraInfo();  
            cameraCount = Camera.getNumberOfCameras(); // get cameras number  
                    
            for ( int camIdx = 0; camIdx < cameraCount;camIdx++ ) {  
                Camera.getCameraInfo( camIdx, cameraInfo ); // get camerainfo  
                if ( cameraInfo.facing ==Camera.CameraInfo.CAMERA_FACING_FRONT ) {   
                    // 代表摄像头的方位,目前有定义值两个分别为CAMERA_FACING_FRONT前置和CAMERA_FACING_BACK后置  
                   return camIdx;  
                }  
            }  
            return -1;  
        }
        private int FindBackCamera(){  
            int cameraCount = 0;  
            Camera.CameraInfo cameraInfo = new Camera.CameraInfo();  
            cameraCount = Camera.getNumberOfCameras(); // get cameras number  
                    
            for ( int camIdx = 0; camIdx < cameraCount;camIdx++ ) {  
                Camera.getCameraInfo( camIdx, cameraInfo ); // get camerainfo  
                if ( cameraInfo.facing ==Camera.CameraInfo.CAMERA_FACING_BACK ) {   
                    // 代表摄像头的方位,目前有定义值两个分别为CAMERA_FACING_FRONT前置和CAMERA_FACING_BACK后置  
                   return camIdx;  
                }  
            }  
            return -1;  
        }  
    public void surfaceCreated(SurfaceHolder holder) {  
            int CammeraIndex=FindBackCamera();  
            if(CammeraIndex==-1){  
                CammeraIndex=FindFrontCamera();  
            }  
            mCamera = Camera.open(CammeraIndex); 
         //设置预览、拍照方向
         mCamera.
    setDisplayOrientation(90);
    }
  • 相关阅读:
    使用SuperWebSocket 构建实时 Web 应用
    slam for Windows 库安装及应用libfreenect2
    《SLAM十四讲》g2o_custombundle在windows轻松调通
    windows下命令行查看库依赖
    zend studio控制台中文乱码
    http协议转
    mysql 字段 增删改
    PHP内部函数
    分层设计
    SecureCRT上传和下载
  • 原文地址:https://www.cnblogs.com/xinzheng/p/8335821.html
Copyright © 2020-2023  润新知