Java Code Examples for android.hardware.Camera.CameraInfo#CAMERA_FACING_FRONT
The following examples show how to use
android.hardware.Camera.CameraInfo#CAMERA_FACING_FRONT .
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: CameraView.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private int getCameraPictureOrientation() { if (getActivity().getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { outputOrientation = getCameraPictureRotation(getActivity().getWindowManager() .getDefaultDisplay() .getOrientation()); } else if (getCameraInfo().facing == CameraInfo.CAMERA_FACING_FRONT) { outputOrientation = (360 - displayOrientation) % 360; } else { outputOrientation = displayOrientation; } return outputOrientation; }
Example 2
Source File: Utils.java From code-scanner with MIT License | 5 votes |
public static int getDisplayOrientation(@NonNull final Context context, @NonNull final CameraInfo cameraInfo) { final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); if (windowManager == null) { throw new CodeScannerException("Unable to access window manager"); } final int degrees; final int rotation = windowManager.getDefaultDisplay().getRotation(); 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; default: if (rotation % 90 == 0) { degrees = (360 + rotation) % 360; } else { throw new CodeScannerException("Invalid display rotation"); } } return ((cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT ? 180 : 360) + cameraInfo.orientation - degrees) % 360; }
Example 3
Source File: CameraApi2Activity.java From pixelvisualcorecamera with Apache License 2.0 | 5 votes |
/** Initializes cameraId state from global preferences. */ @SuppressWarnings("deprecation") private void initCameraSelection() { int cameraIdInt = preferences.getCameraId(); if (cameraIdInt > CameraInfo.CAMERA_FACING_FRONT) { Log.e(TAG, "out of bounds camera id: " + cameraIdInt); cameraIdInt = CameraInfo.CAMERA_FACING_BACK; preferences.setCameraId(cameraIdInt); } cameraId = String.valueOf(cameraIdInt); }
Example 4
Source File: CameraApi1Activity.java From pixelvisualcorecamera with Apache License 2.0 | 5 votes |
private void setCameraIconForCurrentCamera() { ImageButton button = findViewById(R.id.control_camera_selection); switch (cameraId) { case CameraInfo.CAMERA_FACING_BACK: button.setImageResource(R.drawable.ic_camera_rear_white_24); break; case CameraInfo.CAMERA_FACING_FRONT: button.setImageResource(R.drawable.ic_camera_front_white_24); break; default: break; } }
Example 5
Source File: CameraApi1Activity.java From pixelvisualcorecamera with Apache License 2.0 | 5 votes |
/** Initializes cameraId state from global preferences. */ private void initCameraSelection() { cameraId = preferences.getCameraId(); if (cameraId > CameraInfo.CAMERA_FACING_FRONT) { Log.e(TAG, "out of bounds camera id: " + cameraId); cameraId = CameraInfo.CAMERA_FACING_BACK; preferences.setCameraId(cameraId); } }
Example 6
Source File: ICamera.java From MegviiFacepp-Android-SDK with Apache License 2.0 | 5 votes |
/** * 获取照相机旋转角度 */ public int getCameraAngle(Activity activity) { int rotateAngle = 90; CameraInfo info = new 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; } if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { rotateAngle = (info.orientation + degrees) % 360; rotateAngle = (360 - rotateAngle) % 360; // compensate the mirror } else { // back-facing rotateAngle = (info.orientation - degrees + 360) % 360; } return rotateAngle; }
Example 7
Source File: CameraProxy.java From CameraDemo with Apache License 2.0 | 5 votes |
private void setPictureRotate(int orientation) { if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) return; orientation = (orientation + 45) / 90 * 90; int rotation; if (mCameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) { rotation = (mCameraInfo.orientation - orientation + 360) % 360; } else { // back-facing camera rotation = (mCameraInfo.orientation + orientation) % 360; } mLatestRotation = rotation; }
Example 8
Source File: SurfaceGrabberActivity.java From zom-android-matrix with Apache License 2.0 | 5 votes |
public int setCameraDisplayOrientation() { if (camera == null || cameraInfo == null) { return -1; } WindowManager winManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); int rotation = winManager.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 (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (cameraInfo.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (cameraInfo.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; }
Example 9
Source File: CameraView.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public void flipCamera() { if (Camera.getNumberOfCameras() > 1) { cameraId = cameraId == CameraInfo.CAMERA_FACING_BACK ? CameraInfo.CAMERA_FACING_FRONT : CameraInfo.CAMERA_FACING_BACK; onPause(); onResume(); TextSecurePreferences.setDirectCaptureCameraId(getContext(), cameraId); } }
Example 10
Source File: CameraSource.java From mobikul-standalone-pos with MIT License | 4 votes |
/** * Calculates the correct rotation for the given camera id and sets the rotation in the * parameters. It also sets the camera's display orientation and rotation. * * @param parameters the camera parameters for which to set the rotation * @param cameraId the camera id to set rotation based on */ private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) { WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); int degrees = 0; int rotation = windowManager.getDefaultDisplay().getRotation(); 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; default: Log.e(TAG, "Bad rotation value: " + rotation); } CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int angle; int displayAngle; if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) { angle = (cameraInfo.orientation + degrees) % 360; displayAngle = (360 - angle); // compensate for it being mirrored } else { // back-facing angle = (cameraInfo.orientation - degrees + 360) % 360; displayAngle = angle; } // This corresponds to the rotation constants in {@link Frame}. mRotation = angle / 90; camera.setDisplayOrientation(displayAngle); parameters.setRotation(angle); }
Example 11
Source File: CameraSource.java From flutter_mobile_vision with MIT License | 4 votes |
/** * Calculates the correct rotation for the given camera id and sets the rotation in the * parameters. It also sets the camera's display orientation and rotation. * * @param parameters the camera parameters for which to set the rotation * @param cameraId the camera id to set rotation based on */ private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); int degrees = 0; int rotation = windowManager.getDefaultDisplay().getRotation(); 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; default: Log.e(TAG, "Bad rotation value: " + rotation); break; } CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int angle; int displayAngle; if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) { angle = (cameraInfo.orientation + degrees) % 360; displayAngle = (360 - angle); // compensate for it being mirrored //fixed crash when use Camera Front and Device orientation is landscape LEFT if(displayAngle == 360) displayAngle = 0; } else { // back-facing angle = (cameraInfo.orientation - degrees + 360) % 360; displayAngle = angle; } // This corresponds to the rotation constants in {@link Frame}. this.rotation = angle / 90; camera.setDisplayOrientation(displayAngle); parameters.setRotation(angle); }
Example 12
Source File: CameraSource.java From Barcode-Reader with Apache License 2.0 | 4 votes |
/** * Calculates the correct rotation for the given camera id and sets the rotation in the * parameters. It also sets the camera's display orientation and rotation. * * @param parameters the camera parameters for which to set the rotation * @param cameraId the camera id to set rotation based on */ private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) { WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); int degrees = 0; int rotation = windowManager.getDefaultDisplay().getRotation(); 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; default: Log.e(TAG, "Bad rotation value: " + rotation); } CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int angle; int displayAngle; if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) { angle = (cameraInfo.orientation + degrees) % 360; displayAngle = (360 - angle) % 360; // compensate for it being mirrored } else { // back-facing angle = (cameraInfo.orientation - degrees + 360) % 360; displayAngle = angle; } // This corresponds to the rotation constants in {@link Frame}. mRotation = angle / 90; camera.setDisplayOrientation(displayAngle); parameters.setRotation(angle); }
Example 13
Source File: CameraSource.java From fast_qr_reader_view with MIT License | 4 votes |
/** * Calculates the correct rotation for the given camera id and sets the rotation in the * parameters. It also sets the camera's display orientation and rotation. * * @param parameters the camera parameters for which to set the rotation * @param cameraId the camera id to set rotation based on */ private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) { WindowManager windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); int degrees = 0; int rotation = windowManager.getDefaultDisplay().getRotation(); 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; default: Log.e(TAG, "Bad rotation value: " + rotation); } CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int angle; int displayAngle; if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) { angle = (cameraInfo.orientation + degrees) % 360; displayAngle = (360 - angle) % 360; // compensate for it being mirrored } else { // back-facing angle = (cameraInfo.orientation - degrees + 360) % 360; displayAngle = angle; } // This corresponds to the rotation constants. this.rotation = angle / 90; camera.setDisplayOrientation(displayAngle); parameters.setRotation(angle); }
Example 14
Source File: CameraSource.java From trust-wallet-android-source with GNU General Public License v3.0 | 4 votes |
/** * Calculates the correct rotation for the given camera id and sets the rotation in the * parameters. It also sets the camera's display orientation and rotation. * * @param parameters the camera parameters for which to set the rotation * @param cameraId the camera id to set rotation based on */ private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) { WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); int degrees = 0; int rotation = windowManager.getDefaultDisplay().getRotation(); 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; default: Log.e(TAG, "Bad rotation value: " + rotation); } CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int angle; int displayAngle; if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) { angle = (cameraInfo.orientation + degrees) % 360; displayAngle = (360 - angle); // compensate for it being mirrored } else { // back-facing angle = (cameraInfo.orientation - degrees + 360) % 360; displayAngle = angle; } // This corresponds to the rotation constants in {@link Frame}. mRotation = angle / 90; camera.setDisplayOrientation(displayAngle); parameters.setRotation(angle); }
Example 15
Source File: CameraSource.java From Barcode-Reader with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Calculates the correct rotation for the given camera id and sets the rotation in the * parameters. It also sets the camera's display orientation and rotation. * * @param parameters the camera parameters for which to set the rotation * @param cameraId the camera id to set rotation based on */ private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) { WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); int degrees = 0; int rotation = windowManager.getDefaultDisplay().getRotation(); 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; default: Log.e(TAG, "Bad rotation value: " + rotation); } CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int angle; int displayAngle; if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) { angle = (cameraInfo.orientation + degrees) % 360; displayAngle = (360 - angle) % 360; // compensate for it being mirrored } else { // back-facing angle = (cameraInfo.orientation - degrees + 360) % 360; displayAngle = angle; } // This corresponds to the rotation constants in {@link Frame}. mRotation = angle / 90; camera.setDisplayOrientation(displayAngle); parameters.setRotation(angle); }
Example 16
Source File: CameraSource.java From samples-android with Apache License 2.0 | 4 votes |
/** * Calculates the correct rotation for the given camera id and sets the rotation in the * parameters. It also sets the camera's display orientation and rotation. * * @param parameters the camera parameters for which to set the rotation * @param cameraId the camera id to set rotation based on */ private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) { WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); int degrees = 0; int rotation = windowManager.getDefaultDisplay().getRotation(); 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; default: Log.e(TAG, "Bad rotation value: " + rotation); } CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int angle; int displayAngle; if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) { angle = (cameraInfo.orientation + degrees) % 360; displayAngle = (360 - angle) % 360; // compensate for it being mirrored } else { // back-facing angle = (cameraInfo.orientation - degrees + 360) % 360; displayAngle = angle; } // This corresponds to the rotation constants in {@link Frame}. mRotation = angle / 90; camera.setDisplayOrientation(displayAngle); parameters.setRotation(angle); }
Example 17
Source File: SurfaceGrabberActivity.java From zom-android-matrix with Apache License 2.0 | 4 votes |
private int getOtherDirection(int facing) { return (facing == CameraInfo.CAMERA_FACING_BACK) ? CameraInfo.CAMERA_FACING_FRONT : CameraInfo.CAMERA_FACING_BACK; }
Example 18
Source File: CameraSource.java From VehicleInfoOCR with GNU General Public License v3.0 | 4 votes |
/** * Calculates the correct rotation for the given camera id and sets the rotation in the * parameters. It also sets the camera's display orientation and rotation. * * @param parameters the camera parameters for which to set the rotation * @param cameraId the camera id to set rotation based on */ private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) { // Does better job than firebase's rotation compensation : https://firebase.google.com/docs/ml-kit/android/recognize-text // as it also caters to front camera later // Note: Rotation anyway resets the activity!! So we can set it fine from onCreate WindowManager windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); int degrees = 0; int rotation = windowManager.getDefaultDisplay().getRotation(); 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; default: Log.e(TAG, "Bad rotation value: " + rotation); } CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int angle; int displayAngle; if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) { angle = (cameraInfo.orientation + degrees) % 360; displayAngle = (360 - angle) % 360; // compensate for it being mirrored } else { // back-facing angle = (cameraInfo.orientation - degrees + 360) % 360; displayAngle = angle; } // This corresponds to the rotation constants. this.rotation = angle / 90; camera.setDisplayOrientation(displayAngle); parameters.setRotation(angle); }
Example 19
Source File: CameraView.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private boolean isTroublemaker() { return getCameraInfo().facing == CameraInfo.CAMERA_FACING_FRONT && "JWR66Y".equals(Build.DISPLAY) && "yakju".equals(Build.PRODUCT); }
Example 20
Source File: CodeScanner.java From code-scanner with MIT License | 4 votes |
private void initialize() { Camera camera = null; final CameraInfo cameraInfo = new CameraInfo(); final int cameraId = mCameraId; if (cameraId == CAMERA_BACK || cameraId == CAMERA_FRONT) { final int numberOfCameras = Camera.getNumberOfCameras(); final int facing = cameraId == CAMERA_BACK ? CameraInfo.CAMERA_FACING_BACK : CameraInfo.CAMERA_FACING_FRONT; for (int i = 0; i < numberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == facing) { camera = Camera.open(i); mCameraId = i; break; } } } else { camera = Camera.open(cameraId); Camera.getCameraInfo(cameraId, cameraInfo); } if (camera == null) { throw new CodeScannerException("Unable to access camera"); } final Parameters parameters = camera.getParameters(); if (parameters == null) { throw new CodeScannerException("Unable to configure camera"); } final int orientation = Utils.getDisplayOrientation(mContext, cameraInfo); final boolean portrait = Utils.isPortrait(orientation); final Point imageSize = Utils.findSuitableImageSize(parameters, portrait ? mHeight : mWidth, portrait ? mWidth : mHeight); final int imageWidth = imageSize.getX(); final int imageHeight = imageSize.getY(); parameters.setPreviewSize(imageWidth, imageHeight); parameters.setPreviewFormat(ImageFormat.NV21); final Point previewSize = Utils.getPreviewSize(portrait ? imageHeight : imageWidth, portrait ? imageWidth : imageHeight, mWidth, mHeight); final List<String> focusModes = parameters.getSupportedFocusModes(); final boolean autoFocusSupported = focusModes != null && (focusModes.contains(Parameters.FOCUS_MODE_AUTO) || focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)); if (!autoFocusSupported) { mAutoFocusEnabled = false; } final Point viewSize = new Point(mWidth, mHeight); if (autoFocusSupported && mAutoFocusEnabled) { Utils.setAutoFocusMode(parameters, mAutoFocusMode); final Rect frameRect = mScannerView.getFrameRect(); if (frameRect != null) { Utils.configureDefaultFocusArea(parameters, frameRect, previewSize, viewSize, imageWidth, imageHeight, orientation); } } final List<String> flashModes = parameters.getSupportedFlashModes(); final boolean flashSupported = flashModes != null && flashModes.contains(Parameters.FLASH_MODE_TORCH); if (!flashSupported) { mFlashEnabled = false; } final int zoom = mZoom; if (zoom != 0) { Utils.setZoom(parameters, zoom); } Utils.configureFpsRange(parameters); Utils.configureSceneMode(parameters); Utils.configureVideoStabilization(parameters); camera.setParameters(parameters); camera.setDisplayOrientation(orientation); synchronized (mInitializeLock) { final Decoder decoder = new Decoder(mDecoderStateListener, mFormats, mDecodeCallback); mDecoderWrapper = new DecoderWrapper(camera, cameraInfo, decoder, imageSize, previewSize, viewSize, orientation, autoFocusSupported, flashSupported); decoder.start(); mInitialization = false; mInitialized = true; } mMainThreadHandler.post(new FinishInitializationTask(previewSize)); }