List of usage examples for android.hardware Camera getCameraInfo
public static void getCameraInfo(int cameraId, CameraInfo cameraInfo)
From source file:Main.java
/** * Calculates the front camera rotation/* ww w. j a v a2 s . c o m*/ * <p> * This calculation is applied to the output JPEG either via Exif Orientation tag * or by actually transforming the bitmap. (Determined by vendor camera API implementation) * <p> * Note: This is not the same calculation as the display orientation * * @param screenOrientationDegrees Screen orientation in degrees * @return Number of degrees to rotate image in order for it to view correctly. */ public static int calcCameraRotation(int cameraId, int screenOrientationDegrees) { Camera.CameraInfo camInfo = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, camInfo); return (camInfo.orientation + screenOrientationDegrees) % 360; }
From source file:Main.java
/** * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT * or Camera.CameraInfo.CAMERA_FACING_BACK. * @return the default camera id/* ww w. ja v a 2s .c o m*/ */ @TargetApi(Build.VERSION_CODES.GINGERBREAD) private static int getDefaultCameraId(int position) { // Find the total number of cameras available int mNumberOfCameras = Camera.getNumberOfCameras(); // Find the ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int i = 0; i < mNumberOfCameras; ++i) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == position) return i; } return -1; }
From source file:Main.java
/** * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT * or Camera.CameraInfo.CAMERA_FACING_BACK. * @return the default camera id/*from w w w . ja va 2s. c om*/ */ @TargetApi(Build.VERSION_CODES.GINGERBREAD) private static int getDefaultCameraId(int position) { // Find the total number of cameras available int mNumberOfCameras = Camera.getNumberOfCameras(); // Find the ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int i = 0; i < mNumberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == position) { return i; } } return -1; }
From source file:Main.java
/** * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT * or Camera.CameraInfo.CAMERA_FACING_BACK. * @return the default camera on the device. Returns null if camera is not available. *//* w ww.j av a 2 s . c o m*/ @TargetApi(Build.VERSION_CODES.GINGERBREAD) private static int getDefaultCamera(int position) { // Find the total number of cameras available int mNumberOfCameras = Camera.getNumberOfCameras(); // Find the ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int i = 0; i < mNumberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == position) { return i; } } return 0; }
From source file:Main.java
/** * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT * or Camera.CameraInfo.CAMERA_FACING_BACK. * @return the default camera on the device. Returns null if camera is not available. *///from w w w . j a v a 2s.com @TargetApi(Build.VERSION_CODES.GINGERBREAD) private static Camera getDefaultCamera(int position) { // Find the total number of cameras available int mNumberOfCameras = Camera.getNumberOfCameras(); // Find the ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int i = 0; i < mNumberOfCameras; ++i) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == position) return Camera.open(i); } return null; }
From source file:Main.java
/** * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT * or Camera.CameraInfo.CAMERA_FACING_BACK. * @return the default camera on the device. Returns null if camera is not available. *//* w w w. j a va 2 s . c o m*/ @TargetApi(Build.VERSION_CODES.GINGERBREAD) public static Camera getDefaultCamera(int position) { // Find the total number of cameras available int mNumberOfCameras = Camera.getNumberOfCameras(); // Find the ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int i = 0; i < mNumberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == position) { try { return Camera.open(i); } catch (Exception e) { e.printStackTrace(); } } } return null; }
From source file:Main.java
/** * * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT * or Camera.CameraInfo.CAMERA_FACING_BACK. * @return the default camera on the device. Returns null if camera is not available. *///from w ww . ja va 2 s .c o m @TargetApi(Build.VERSION_CODES.GINGERBREAD) private static Camera getDefaultCamera(int position) { // Find the total number of cameras available int mNumberOfCameras = Camera.getNumberOfCameras(); // Find the ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int i = 0; i < mNumberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == position) { return Camera.open(i); } } return null; }
From source file:Main.java
/** * Calculates the clockwise rotation applied to the camera such that the picture will be aligned with the screen * orientation.// w w w . ja va 2s. co m * * @param activity the {@link Activity}. * @param cameraId id of the camera. * @return the clockwise rotation in degrees. */ public static int getCameraScreenOrientation(Activity activity, int cameraId) { int cameraScreenOrientation = CAMERA_SCREEN_ORIENTATION_0; // Get camera info. CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); // Get screen orientation. int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = SCREEN_ROTATION_0; switch (rotation) { case Surface.ROTATION_0: degrees = SCREEN_ROTATION_0; break; case Surface.ROTATION_90: degrees = SCREEN_ROTATION_90; break; case Surface.ROTATION_180: degrees = SCREEN_ROTATION_180; break; case Surface.ROTATION_270: degrees = SCREEN_ROTATION_270; break; } /* * Calculate result based on camera and screen orientation. */ if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { // Calculate relative rotation between camera and screen. cameraScreenOrientation = (info.orientation + degrees) % 360; // Account for mirroring. cameraScreenOrientation = (360 - cameraScreenOrientation) % 360; } else { // Calculate relative rotation between camera and screen. cameraScreenOrientation = (info.orientation - degrees + 360) % 360; } return cameraScreenOrientation; }
From source file:Main.java
public static int getDefaultCameraId(int position) { int mNumberOfCameras = Camera.getNumberOfCameras(); // Find the ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int i = 0; i < mNumberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == position) { return i; }/*from w ww .j a v a 2 s.c o m*/ } return -1; }
From source file:org.webrtc.videoengine.VideoCaptureDeviceInfoAndroid.java
private static String getDeviceInfo() { try {/*from ww w. j a va 2 s. c o m*/ JSONArray devices = new JSONArray(); for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(i, info); String uniqueName = deviceUniqueName(i, info); JSONObject cameraDict = new JSONObject(); devices.put(cameraDict); List<Size> supportedSizes; List<int[]> supportedFpsRanges; Camera camera = null; try { camera = Camera.open(i); Parameters parameters = camera.getParameters(); supportedSizes = parameters.getSupportedPreviewSizes(); supportedFpsRanges = parameters.getSupportedPreviewFpsRange(); Log.d(TAG, uniqueName); } catch (RuntimeException e) { Log.e(TAG, "Failed to open " + uniqueName + ", skipping", e); continue; } finally { if (camera != null) { camera.release(); } } JSONArray sizes = new JSONArray(); for (Size supportedSize : supportedSizes) { JSONObject size = new JSONObject(); size.put("width", supportedSize.width); size.put("height", supportedSize.height); sizes.put(size); } JSONArray mfpsRanges = new JSONArray(); for (int[] range : supportedFpsRanges) { JSONObject mfpsRange = new JSONObject(); // Android SDK deals in integral "milliframes per second" // (i.e. fps*1000, instead of floating-point frames-per-second) so we // preserve that through the Java->C++->Java round-trip. mfpsRange.put("min_mfps", range[Parameters.PREVIEW_FPS_MIN_INDEX]); mfpsRange.put("max_mfps", range[Parameters.PREVIEW_FPS_MAX_INDEX]); mfpsRanges.put(mfpsRange); } cameraDict.put("name", uniqueName); cameraDict.put("front_facing", isFrontFacing(info)).put("orientation", info.orientation) .put("sizes", sizes).put("mfpsRanges", mfpsRanges); } String ret = devices.toString(2); Log.d(TAG, ret); return ret; } catch (JSONException e) { throw new RuntimeException(e); } }