List of usage examples for android.hardware Camera getCameraInfo
public static void getCameraInfo(int cameraId, CameraInfo cameraInfo)
From source file:Main.java
public static void setCameraDisplayOrientation(int rotation, 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;/*ww w.j a va 2 s .c om*/ 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); }
From source file:Main.java
private static void obtainCameraRatios() { for (int i = 0; i < Camera.getNumberOfCameras(); i++) { Camera camera = Camera.open(i);//from w w w. ja va2 s . c o m Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(i, info); if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { frontCameraRatio = camera.getParameters().getPreferredPreviewSizeForVideo(); } else { backCameraRatio = camera.getParameters().getPreferredPreviewSizeForVideo(); } camera.release(); } }
From source file:Main.java
public static int getCameraId(int cameraFacing) { int count = Camera.getNumberOfCameras(); if (count > 0) { Camera.CameraInfo info = new Camera.CameraInfo(); for (int i = 0; i < count; i++) { Camera.getCameraInfo(i, info); if (info.facing == cameraFacing) { return i; }/*from w w w . ja va 2 s . com*/ } } return -1; }
From source file:Main.java
private static int findCamera(int type) { int cameraId = -1; // Search for the front facing camera int numberOfCameras = Camera.getNumberOfCameras(); for (int i = 0; i < numberOfCameras; i++) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(i, info); if (info.facing == type) { cameraId = i;//from w w w.j a v a2 s . c o m break; } } return cameraId; }
From source file:Main.java
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; }/*from ww w. ja va 2s. c om*/ } return false; }
From source file:Main.java
public static int setCameraDisplayOrientation(int cameraId, Camera camera, int displayRotation) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int degrees = 0; switch (displayRotation) { case Surface.ROTATION_0: degrees = 0;// w w w .j av a 2 s . c om break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int camRotationDegree = 0; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { camRotationDegree = (info.orientation + degrees) % 360; camRotationDegree = (360 - camRotationDegree) % 360; // compensate the mirror } else { camRotationDegree = (info.orientation - degrees + 360) % 360; } if (camera != null) { camera.setDisplayOrientation(camRotationDegree); } return camRotationDegree; }
From source file:Main.java
/** * @return front camera// w w w.j a va 2 s . c om */ public static Camera getFrontCamera() { CameraInfo cameraInfo = new CameraInfo(); int cameraCount = Camera.getNumberOfCameras(); for (int i = 0; i < cameraCount; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { cameraId = i; return Camera.open(i); } } return null; }
From source file:Main.java
public static int determineDisplayOrientation(Activity activity, int defaultCameraId) { if (VERSION.SDK_INT <= 8) { return 0; }/*from w w w.j a v a2 s . com*/ CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(defaultCameraId, cameraInfo); int degrees = getRotationAngle(activity); if (cameraInfo.facing == 1) { return (360 - ((cameraInfo.orientation + degrees) % 360)) % 360; } return ((cameraInfo.orientation - degrees) + 360) % 360; }
From source file:Main.java
public static int HasBackCamera() { int numberOfCameras = Camera.getNumberOfCameras(); CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < numberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == CAMERA_FACING_BACK) { return i; }/*from www . j a v a 2 s . c o m*/ } return 2; }
From source file:Main.java
public static boolean hasFrontCamera() { for (int i = 0; i < Camera.getNumberOfCameras(); i++) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { return true; }//from w w w.j a v a 2 s . c o m } return false; }