List of usage examples for android.hardware Camera getCameraInfo
public static void getCameraInfo(int cameraId, CameraInfo cameraInfo)
From source file:Main.java
static int calculateOrientation(Activity activity, int cameraId) { if (cameraId == NO_CAMERA) return 0; DisplayMetrics dm = new DisplayMetrics(); Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int cameraRotationOffset = info.orientation; activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int currentScreenRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (currentScreenRotation) { case Surface.ROTATION_0: degrees = 0;//from w w w .j av a 2s .c o m break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int orientation; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { orientation = (cameraRotationOffset + degrees) % 360; orientation = (360 - orientation) % 360; } else { orientation = (cameraRotationOffset - degrees + 360) % 360; } return orientation; }
From source file:Main.java
/** * Checks whether this device support a front camera. * @return true if this device support a front camera, false otherwise *///w ww. ja v a 2 s .c om public static boolean hasFrontFacingDevice() { for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { Camera.CameraInfo info = new Camera.CameraInfo(); try { Camera.getCameraInfo(i, info); if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { return true; } } catch (Exception e) { // do nothing. } } return false; }
From source file:Main.java
public static int getPortraitCamearaDisplayOrientation(Context context, int cameraId, boolean isFrontCamera) { if (cameraId < 0 || cameraId > getCameraNumber()) { return -1; }//from w w w. java 2 s. c o m Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int rotation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).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 (isFrontCamera) { result = (cameraInfo.orientation + degrees) % 360; result = (360 - result) % 360; } else { result = (cameraInfo.orientation - degrees + 360) % 360; } return result; }
From source file:Main.java
/** * @return a mapping of all camera ids to matching camera info */// ww w . ja v a 2s .co m public static Map<Integer, Camera.CameraInfo> getCameras() { Map<Integer, Camera.CameraInfo> cameraMap = new HashMap<Integer, Camera.CameraInfo>(); int numberOfCameras = Camera.getNumberOfCameras(); Camera.CameraInfo cameraInfo = null; for (int i = 0; i < numberOfCameras; i++) { cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(i, cameraInfo); cameraMap.put(i, cameraInfo); } return cameraMap; }
From source file:Main.java
public static Camera.CameraInfo[] getCameraArray(Context context) { Camera.CameraInfo[] cameraArray = null; if (isCameraPresent(context)) { int numCameras = Camera.getNumberOfCameras(); if (numCameras > 0) { cameraArray = new Camera.CameraInfo[numCameras]; for (int ii = 0; ii < numCameras; ++ii) { cameraArray[ii] = new Camera.CameraInfo(); Camera.getCameraInfo(ii, cameraArray[ii]); }/* w ww. j a va2 s .c o m*/ } } return cameraArray; }
From source file:Main.java
/** * Get camera id of specified camera face * @param cameraFace must be one of {@link CameraInfo#CAMERA_FACING_FRONT} * and {@link CameraInfo#CAMERA_FACING_BACK} * @return the camera id/*from w w w .ja va 2 s . co m*/ */ public static int getCameraId(int cameraFace) { int cameraId = 0; int numberOfCameras = Camera.getNumberOfCameras(); CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < numberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == cameraFace) { cameraId = i; break; } } return cameraId; }
From source file:Main.java
static int calculateOrientation(Activity activity, int cameraId) { if (cameraId == NO_CAMERA) return 0; DisplayMetrics dm = new DisplayMetrics(); Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int cameraRotationOffset = info.orientation; Log.w(TAG, "cameraRotationOffset = " + cameraRotationOffset); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int currentScreenRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); Log.w(TAG, "currentScreenRotation = " + currentScreenRotation); int degrees = 0; switch (currentScreenRotation) { case Surface.ROTATION_0: degrees = 0;//from ww w.jav a 2 s .co m break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } Log.w(TAG, "degrees = " + degrees); int orientation; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { orientation = (cameraRotationOffset + degrees) % 360; orientation = (360 - orientation) % 360; } else { orientation = (cameraRotationOffset - degrees + 360) % 360; } Log.w(TAG, "orientation = " + orientation); return orientation; }
From source file:Main.java
public static Bitmap makeSquare(File file, int cameraID) { int width;//from w w w. j a v a2 s . com int height; Matrix matrix = new Matrix(); Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraID, info); // Convert ByteArray to Bitmap Bitmap bitPic = decodeSampledBitmapFromFile(destinationFile.getAbsolutePath(), 800, 800);//BitmapFactory.decodeByteArray(data, 0, data.length); width = bitPic.getWidth(); height = bitPic.getHeight(); // Perform matrix rotations/mirrors depending on camera that took the photo if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1 }; Matrix matrixMirrorY = new Matrix(); matrixMirrorY.setValues(mirrorY); matrix.postConcat(matrixMirrorY); } matrix.postRotate(90); // Create new Bitmap out of the old one Bitmap bitPicFinal = Bitmap.createBitmap(bitPic, 0, 0, width, height, matrix, true); bitPic.recycle(); int desWidth; int desHeight; desWidth = bitPicFinal.getWidth(); desHeight = desWidth; Bitmap croppedBitmap = Bitmap.createBitmap(bitPicFinal, 0, bitPicFinal.getHeight() / 2 - bitPicFinal.getWidth() / 2, desWidth, desHeight); croppedBitmap = Bitmap.createScaledBitmap(croppedBitmap, 528, 528, true); return croppedBitmap; }
From source file:Main.java
static int calculateOrientationHint(Activity activity, int cameraId) { if (cameraId == NO_CAMERA) return 0; DisplayMetrics dm = new DisplayMetrics(); Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int cameraRotationOffset = info.orientation; Log.w(TAG, "OrientationHint cameraRotationOffset = " + cameraRotationOffset); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int currentScreenRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); Log.w(TAG, "OrientationHint currentScreenRotation = " + currentScreenRotation); int degrees = 0; switch (currentScreenRotation) { case Surface.ROTATION_0: degrees = 0;//from w ww .ja v a 2 s .com break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } Log.w(TAG, "OrientationHint degrees = " + degrees); int orientation; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { orientation = (cameraRotationOffset + degrees) % 360; if (degrees != 0) { orientation = (360 - orientation) % 360; } } else { orientation = (cameraRotationOffset - degrees + 360) % 360; } Log.w(TAG, "orientationHint = " + orientation); return orientation; }
From source file:Main.java
public static int getCameraOrientation(int cameraId) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); return info.orientation; }