Java Code Examples for android.hardware.Camera#getCameraInfo()
The following examples show how to use
android.hardware.Camera#getCameraInfo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextureCameraActivity.java From android-openGL-canvas with Apache License 2.0 | 6 votes |
private void openCamera() { Camera.CameraInfo info = new Camera.CameraInfo(); // Try to find a front-facing camera (e.g. for videoconferencing). int numCameras = Camera.getNumberOfCameras(); for (int i = 0; i < numCameras; i++) { Camera.getCameraInfo(i, info); if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { mCamera = Camera.open(i); break; } } if (mCamera == null) { mCamera = Camera.open(); // opens first back-facing camera } Camera.Parameters parms = mCamera.getParameters(); CameraUtils.choosePreviewSize(parms, 1280, 720); }
Example 2
Source File: CameraFragment.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create a container that will hold a SurfaceView for camera previews mPreview = new Preview(this.getActivity()); // Find the total number of cameras available mNumberOfCameras = Camera.getNumberOfCameras(); // Find the ID of the rear-facing ("default") camera CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < mNumberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { mCurrentCamera = mDefaultCameraId = i; } } setHasOptionsMenu(mNumberOfCameras > 1); }
Example 3
Source File: OpenCamera.java From CameraBlur with Apache License 2.0 | 6 votes |
private int findBestCamera() { int cameraId = -1; //Search for the back facing camera //get the number of cameras int numberOfCameras = Camera.getNumberOfCameras(); //for every camera check for (int i = 0; i < numberOfCameras; i++) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(i, info); if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { cameraId = i; break; } cameraId = i; } return cameraId; }
Example 4
Source File: JCameraView.java From Tok-Android with GNU General Public License v3.0 | 6 votes |
/** * 获得可用的相机,并设置前后摄像机的ID */ private void findAvailableCameras() { Camera.CameraInfo info = new Camera.CameraInfo(); int numCamera = Camera.getNumberOfCameras(); for (int i = 0; i < numCamera; i++) { Camera.getCameraInfo(i, info); // 找到了前置摄像头 if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { CAMERA_FRONT_POSITION = info.facing; } // 找到了后置摄像头 if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { CAMERA_POST_POSITION = info.facing; } } }
Example 5
Source File: TakePhotoCompatUtils.java From ImagePicker with Apache License 2.0 | 5 votes |
/** * 检查设备是否有摄像头 * * @return */ public static boolean hasCamera() { final int cameraCount = Camera.getNumberOfCameras(); Camera.CameraInfo info = new Camera.CameraInfo(); for (int i = 0; i < cameraCount; i++) { Camera.getCameraInfo(i, info); if (info.facing == CAMERA_FACING_BACK) { return true; } } return false; }
Example 6
Source File: CameraUtil.java From RxCamera with MIT License | 5 votes |
public static Camera.CameraInfo getCameraInfo(int id) { if (id >= 0 && id < getCameraNumber()) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(id, cameraInfo); return cameraInfo; } return null; }
Example 7
Source File: CameraSource.java From BarcodeReaderSample with MIT License | 5 votes |
/** * Gets the id for the camera specified by the direction it is facing. Returns -1 if no such * camera was found. * * @param facing the desired camera (front-facing or rear-facing) */ private static int getIdForRequestedCamera(int facing) { CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == facing) { return i; } } return -1; }
Example 8
Source File: OpenCameraInterface.java From BarcodeScanner with Apache License 2.0 | 5 votes |
/** * Opens a rear-facing camera with {@link Camera#open(int)}, if one exists, * or opens camera 0. */ public static Camera open() { int numCameras = Camera.getNumberOfCameras(); if (numCameras == 0) { Log.w(TAG, "No cameras!"); return null; } int index = 0; while (index < numCameras) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(index, cameraInfo); // CAMERA_FACING_BACK:手机背面的摄像头 if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { break; } index++; } Camera camera; if (index < numCameras) { Log.i(TAG, "Opening camera #" + index); camera = Camera.open(index); } else { Log.i(TAG, "No camera facing back; returning camera #0"); camera = Camera.open(0); } return camera; }
Example 9
Source File: CameraSource.java From Moneycim with MIT License | 5 votes |
/** * Gets the id for the camera specified by the direction it is facing. Returns -1 if no such * camera was found. * * @param facing the desired camera (front-facing or rear-facing) */ private static int getIdForRequestedCamera(int facing) { CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == facing) { return i; } } return -1; }
Example 10
Source File: CameraMgr.java From FamilyChat with Apache License 2.0 | 5 votes |
/** * 检查是否有摄像头 * * @param facing 前置还是后置 */ private boolean checkCameraFacing(int facing) { int cameraCount = Camera.getNumberOfCameras(); Camera.CameraInfo info = new Camera.CameraInfo(); for (int i = 0; i < cameraCount; i++) { Camera.getCameraInfo(i, info); if (facing == info.facing) { return true; } } return false; }
Example 11
Source File: CameraUtils.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
/** * 摄像机是否支持前置拍照 * @return */ static boolean isSupportFrontCamera() { final int cameraCount = Camera.getNumberOfCameras(); Camera.CameraInfo info = new Camera.CameraInfo(); for (int i = 0; i < cameraCount; i++) { Camera.getCameraInfo(i, info); if (info.facing == 1) { return true; } } return false; }
Example 12
Source File: CameraPreviewView.java From Camdroid with Apache License 2.0 | 5 votes |
public void createCamera() { Log.d(TAG, "createCamera()"); // Open the default i.e. the first rear facing camera. int cameraIndex = CameraManager.firstBackFacingCamera(); this.mCamera = CameraManager.openCamera(cameraIndex); if (this.mCamera == null) { return; } CameraManager.initializeCamera(this.mCamera); Log.d(TAG, "camera created"); CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraIndex, cameraInfo); boolean canDisableSystemShutterSound = false; if (cameraInfo.canDisableShutterSound) { canDisableSystemShutterSound = this.mCamera .enableShutterSound(false); } this.mAutoFocusManager = new AutoFocusManager(this.getContext() .getApplicationContext(), this.mCamera, canDisableSystemShutterSound); }
Example 13
Source File: CameraSource.java From quickstart-android with Apache License 2.0 | 5 votes |
/** * Gets the id for the camera specified by the direction it is facing. Returns -1 if no such * camera was found. * * @param facing the desired camera (front-facing or rear-facing) */ private static int getIdForRequestedCamera(int facing) { CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == facing) { return i; } } return -1; }
Example 14
Source File: CameraUtil.java From TextOcrExample with Apache License 2.0 | 5 votes |
/** * 保证预览方向正确 * * @param activity * @param cameraId * @param camera */ public void setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay() .getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: 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); }
Example 15
Source File: VideoCapture.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
private ChromiumCameraInfo(int index) { mId = index; mCameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(index, mCameraInfo); }
Example 16
Source File: Camera1ApiManager.java From rtmp-rtsp-stream-client-java with Apache License 2.0 | 4 votes |
private void start() { if (!checkCanOpen()) { throw new CameraOpenException("This camera resolution cant be opened"); } yuvBuffer = new byte[width * height * 3 / 2]; try { camera = Camera.open(cameraSelect); Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraSelect, info); isFrontCamera = info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT; isPortrait = context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(width, height); parameters.setPreviewFormat(imageFormat); int[] range = adaptFpsRange(fps, parameters.getSupportedPreviewFpsRange()); parameters.setPreviewFpsRange(range[0], range[1]); List<String> supportedFocusModes = parameters.getSupportedFocusModes(); if (supportedFocusModes != null && !supportedFocusModes.isEmpty()) { if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } else if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) { parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); } else { parameters.setFocusMode(supportedFocusModes.get(0)); } } camera.setParameters(parameters); camera.setDisplayOrientation(rotation); if (surfaceView != null) { camera.setPreviewDisplay(surfaceView.getHolder()); camera.addCallbackBuffer(yuvBuffer); camera.setPreviewCallbackWithBuffer(this); } else if (textureView != null) { camera.setPreviewTexture(textureView.getSurfaceTexture()); camera.addCallbackBuffer(yuvBuffer); camera.setPreviewCallbackWithBuffer(this); } else { camera.setPreviewTexture(surfaceTexture); } camera.startPreview(); running = true; if (cameraCallbacks != null) { cameraCallbacks.onCameraChanged(isFrontCamera); } Log.i(TAG, width + "X" + height); } catch (IOException e) { Log.e(TAG, "Error", e); } }
Example 17
Source File: CameraView.java From deltachat-android with GNU General Public License v3.0 | 4 votes |
private @NonNull CameraInfo getCameraInfo() { final CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); return info; }
Example 18
Source File: Camera1View.java From oneHookLibraryAndroid with Apache License 2.0 | 4 votes |
/** * Restart the camera. * * @throws IOException exception */ protected void restartCamera() throws IOException { if (mCamera == null) { return; } final Camera.Parameters params = mCamera.getParameters(); final SizePair sp = generateValidPreviewSize(mCamera, mDesiredPreviewViewSize.x, mDesiredPreviewViewSize.y); params.setPictureSize(sp.mPicture.getWidth(), sp.mPicture.getHeight()); params.setPreviewSize(sp.mPicture.getWidth(), sp.mPicture.getHeight()); params.setPictureFormat(PixelFormat.JPEG); params.setJpegQuality(mCameraConfig.jpegQuality); final Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); final Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(mCameraConfig.cameraInfo, cameraInfo); if (mCameraConfig.cameraInfo == CameraConfig.BACK_FACING) { /* back camera */ /* TODO orientation calculation*/ if (display.getRotation() == Surface.ROTATION_0) { mCamera.setDisplayOrientation(90); } else if (display.getRotation() == Surface.ROTATION_90) { } else if (display.getRotation() == Surface.ROTATION_180) { } else if (display.getRotation() == Surface.ROTATION_270) { mCamera.setDisplayOrientation(180); } } else { /* front camera */ final int degrees; if (display.getRotation() == Surface.ROTATION_0) { degrees = 0; } else if (display.getRotation() == Surface.ROTATION_90) { degrees = 90; } else if (display.getRotation() == Surface.ROTATION_180) { degrees = 180; } else { degrees = 270; } int result = (cameraInfo.orientation + degrees) % 360; result = (360 - result) % 360; mCamera.setDisplayOrientation(result); params.setRotation(result); } /* make sure to auto focus */ if (params.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } else if (params.getSupportedFocusModes().size() > 0) { params.setFocusMode(params.getSupportedFocusModes().get((0))); } mCamera.setParameters(params); mCamera.setPreviewDisplay(mHolder); mCamera.startPreview(); }
Example 19
Source File: OpenCameraInterface.java From AndroidWallet with GNU General Public License v3.0 | 4 votes |
/** * Opens the requested camera with {@link Camera#open(int)}, if one exists. * * @param cameraId * camera ID of the camera to use. A negative value means * "no preference" * @return handle to {@link Camera} that was opened */ public static Camera open(int cameraId) { int numCameras = Camera.getNumberOfCameras(); if (numCameras == 0) { Log.w(TAG, "No cameras!"); return null; } boolean explicitRequest = cameraId >= 0; if (!explicitRequest) { // Select a camera if no explicit camera requested int index = 0; while (index < numCameras) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(index, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { break; } index++; } cameraId = index; } Camera camera; if (cameraId < numCameras) { Log.i(TAG, "Opening camera #" + cameraId); camera = Camera.open(cameraId); } else { if (explicitRequest) { Log.w(TAG, "Requested camera does not exist: " + cameraId); camera = null; } else { Log.i(TAG, "No camera facing back_black; returning camera #0"); camera = Camera.open(0); } } return camera; }
Example 20
Source File: OpenCameraInterface.java From zxing with MIT License | 4 votes |
/** * Opens the requested camera with {@link Camera#open(int)}, if one exists. * * @param cameraId camera ID of the camera to use. A negative value means "no preference" * @return handle to {@link Camera} that was opened */ @SuppressLint("NewApi") public static Camera open(int cameraId) { int numCameras = Camera.getNumberOfCameras(); if (numCameras == 0) { Log.w(TAG, "No cameras!"); return null; } boolean explicitRequest = cameraId >= 0; if (!explicitRequest) { // Select a camera if no explicit camera requested int index = 0; while (index < numCameras) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(index, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { break; } index++; } cameraId = index; } Camera camera; if (cameraId < numCameras) { Log.i(TAG, "Opening camera #" + cameraId); camera = Camera.open(cameraId); } else { if (explicitRequest) { Log.w(TAG, "Requested camera does not exist: " + cameraId); camera = null; } else { Log.i(TAG, "No camera facing back; returning camera #0"); camera = Camera.open(0); } } return camera; }