Java Code Examples for android.view.Surface#ROTATION_90
The following examples show how to use
android.view.Surface#ROTATION_90 .
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: CompassView.java From android with Apache License 2.0 | 6 votes |
private void configureDeviceAngle() { switch (mDeviceOrientation) { case Surface.ROTATION_0: // Portrait SensorManager.remapCoordinateSystem(mRotation, SensorManager.AXIS_X, SensorManager.AXIS_Y, mRotationMapped); break; case Surface.ROTATION_90: // Landscape SensorManager.remapCoordinateSystem(mRotation, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_Z, mRotationMapped); break; case Surface.ROTATION_180: // Portrait SensorManager.remapCoordinateSystem(mRotation, SensorManager.AXIS_MINUS_X, SensorManager.AXIS_MINUS_Y, mRotationMapped); break; case Surface.ROTATION_270: // Landscape SensorManager.remapCoordinateSystem(mRotation, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_Z, mRotationMapped); break; } }
Example 2
Source File: Camera2BasicFragment.java From android-object-distance with Apache License 2.0 | 6 votes |
/** * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`. * This method should be called after the camera preview size is determined in * setUpCameraOutputs and also the size of `mTextureView` is fixed. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` */ private void configureTransform(int viewWidth, int viewHeight) { Activity activity = getActivity(); if (null == mTextureView || null == mPreviewSize || null == activity) { return; } int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); Matrix matrix = new Matrix(); RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth()); float centerX = viewRect.centerX(); float centerY = viewRect.centerY(); if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); float scale = Math.max( (float) viewHeight / mPreviewSize.getHeight(), (float) viewWidth / mPreviewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); } else if (Surface.ROTATION_180 == rotation) { matrix.postRotate(180, centerX, centerY); } mTextureView.setTransform(matrix); }
Example 3
Source File: OrientationManagerImpl.java From Camera2 with Apache License 2.0 | 6 votes |
private static int getDisplayRotation(Activity activity) { int rotation = activity.getWindowManager().getDefaultDisplay() .getRotation(); switch (rotation) { case Surface.ROTATION_0: return 0; case Surface.ROTATION_90: return 90; case Surface.ROTATION_180: return 180; case Surface.ROTATION_270: return 270; } return 0; }
Example 4
Source File: CameraConnectionFragment.java From dbclf with Apache License 2.0 | 6 votes |
/** * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`. * This method should be called after the camera preview size is determined in * setUpCameraOutputs and also the size of `mTextureView` is fixed. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` */ private void configureTransform(final int viewWidth, final int viewHeight) { final Activity activity = getActivity(); if (null == textureView || null == previewSize || null == activity) { return; } final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); final Matrix matrix = new Matrix(); final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth()); final float centerX = viewRect.centerX(); final float centerY = viewRect.centerY(); if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); final float scale = Math.max( (float) viewHeight / previewSize.getHeight(), (float) viewWidth / previewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); } else if (Surface.ROTATION_180 == rotation) { matrix.postRotate(180, centerX, centerY); } textureView.setTransform(matrix); }
Example 5
Source File: Util.java From VideoRecorder with Apache License 2.0 | 6 votes |
public static int getRotationAngle(int rotation) { 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; default: break; } return degrees; }
Example 6
Source File: CameraConnectionFragment.java From android-yolo-v2 with Do What The F*ck You Want To Public License | 6 votes |
/** * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`. * This method should be called after the camera preview size is determined in * setUpCameraOutputs and also the size of `mTextureView` is fixed. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` */ private void configureTransform(final int viewWidth, final int viewHeight) { final Activity activity = getActivity(); if (null == textureView || null == previewSize || null == activity) { return; } final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); final Matrix matrix = new Matrix(); final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth()); final float centerX = viewRect.centerX(); final float centerY = viewRect.centerY(); if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); final float scale = Math.max( (float) viewHeight / previewSize.getHeight(), (float) viewWidth / previewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); } else if (Surface.ROTATION_180 == rotation) { matrix.postRotate(180, centerX, centerY); } textureView.setTransform(matrix); }
Example 7
Source File: CameraManager.java From Viewer with Apache License 2.0 | 5 votes |
private int calculateDisplayRotation() { // http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int) int rotation = displayConfiguration.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 == Camera.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; } Log.i(TAG, "Camera Display Orientation: " + result); return result; }
Example 8
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 9
Source File: CameraSession.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private int getDisplayOrientation(Camera.CameraInfo info, boolean isStillCapture) { WindowManager mgr = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE); int rotation = mgr.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 displayOrientation; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { displayOrientation = (info.orientation + degrees) % 360; displayOrientation = (360 - displayOrientation) % 360; if (!isStillCapture && displayOrientation == 90) { displayOrientation = 270; } if (!isStillCapture && "Huawei".equals(Build.MANUFACTURER) && "angler".equals(Build.PRODUCT) && displayOrientation == 270) { displayOrientation = 90; } } else { displayOrientation = (info.orientation - degrees + 360) % 360; } return displayOrientation; }
Example 10
Source File: CameraEngine.java From TikTok with Apache License 2.0 | 5 votes |
/** * --------------- 获得系统默认摄像头旋转的角度 ------------------ * @param cameraId 摄像头Id * @return */ public static int getRightCameraOrientation(int cameraId) { Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); // int rotation = context.getWindowManager().getDefaultDisplay() // .getRotation(); int degrees = 90; switch (surfaceRotation) { 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; } return result; }
Example 11
Source File: Camera2VideoFragment.java From patrol-android with GNU General Public License v3.0 | 5 votes |
/** * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`. * This method should not to be called until the camera preview size is determined in * openCamera, or until the size of `mTextureView` is fixed. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` */ private void configureTransform(int viewWidth, int viewHeight) { Activity activity = getActivity(); if (null == mTextureView || null == mPreviewSize || null == activity) { return; } int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); final Matrix matrix = new Matrix(); RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth()); float centerX = viewRect.centerX(); float centerY = viewRect.centerY(); if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); float scale = Math.max( (float) viewHeight / mPreviewSize.getHeight(), (float) viewWidth / mPreviewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); } activity.runOnUiThread(new Runnable() { @Override public void run() { mTextureView.setTransform(matrix); } }); }
Example 12
Source File: CameraActivity.java From next18-ai-in-motion with Apache License 2.0 | 5 votes |
protected int getScreenOrientation() { switch (getWindowManager().getDefaultDisplay().getRotation()) { case Surface.ROTATION_270: return 270; case Surface.ROTATION_180: return 180; case Surface.ROTATION_90: return 90; default: return 0; } }
Example 13
Source File: CameraConnectionFragment.java From android-hpe with MIT License | 5 votes |
/** * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`. * This method should be called after the camera preview size is determined in * setUpCameraOutputs and also the size of `mTextureView` is fixed. * * @param viewWidth The width of `mTextureView` * @param viewHeight The height of `mTextureView` */ @DebugLog private void configureTransform(final int viewWidth, final int viewHeight) { final Activity activity = getActivity(); if (textureView == null || previewSize == null || activity == null) { return; } final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); final Matrix matrix = new Matrix(); final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth()); final float centerX = viewRect.centerX(); final float centerY = viewRect.centerY(); if(rotation == Surface.ROTATION_90) { //Log.d(TAG, "Rotation is Surface.ROTATION_90"); bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); final float scale = Math.max( (float) viewHeight / previewSize.getHeight(), (float) viewWidth / previewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(-90, centerX, centerY); } /*else if(rotation == Surface.ROTATION_180) { Log.d(TAG, "Rotation is Surface.ROTATION_180"); matrix.postRotate(180, centerX, centerY); } else if(rotation == Surface.ROTATION_270) { Log.d(TAG, "Rotation is Surface.ROTATION_270"); bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); final float scale = Math.max( (float) viewHeight / previewSize.getHeight(), (float) viewWidth / previewSize.getWidth()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); }*/ textureView.setTransform(matrix); }
Example 14
Source File: Preview.java From cordova-plugin-camera-preview with MIT License | 5 votes |
private void setCameraDisplayOrientation() { Camera.CameraInfo info = new Camera.CameraInfo(); int rotation = ((Activity) getContext()).getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; DisplayMetrics dm = new DisplayMetrics(); Camera.getCameraInfo(cameraId, info); ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(dm); 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; } facing = info.facing; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { displayOrientation = (info.orientation + degrees) % 360; displayOrientation = (360 - displayOrientation) % 360; } else { displayOrientation = (info.orientation - degrees + 360) % 360; } Log.d(TAG, "screen is rotated " + degrees + "deg from natural"); Log.d(TAG, (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT ? "front" : "back") + " camera is oriented -" + info.orientation + "deg from natural"); Log.d(TAG, "need to rotate preview " + displayOrientation + "deg"); mCamera.setDisplayOrientation(displayOrientation); }
Example 15
Source File: SensorInterpreter.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("SuspiciousNameCombination") public float[] interpretSensorEvent(@NonNull Context context, @Nullable SensorEvent event) { if (event == null) { return null; } float[] rotationVector = getRotationVectorFromSensorEvent(event); if (!mTargeted) { setTargetVector(rotationVector); return null; } SensorManager.getRotationMatrixFromVector(mRotationMatrix, rotationVector); int rotation = ((WindowManager) context .getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay() .getRotation(); if (rotation == Surface.ROTATION_0) { SensorManager.getAngleChange(mTiltVector, mRotationMatrix, mTargetMatrix); } else { switch (rotation) { case Surface.ROTATION_90: SensorManager.remapCoordinateSystem(mRotationMatrix, AXIS_Y, AXIS_MINUS_X, mOrientedRotationMatrix); break; case Surface.ROTATION_180: SensorManager.remapCoordinateSystem(mRotationMatrix, AXIS_MINUS_X, AXIS_MINUS_Y, mOrientedRotationMatrix); break; case Surface.ROTATION_270: SensorManager.remapCoordinateSystem(mRotationMatrix, AXIS_MINUS_Y, AXIS_X, mOrientedRotationMatrix); break; } SensorManager.getAngleChange(mTiltVector, mOrientedRotationMatrix, mTargetMatrix); } for (int i = 0; i < mTiltVector.length; i++) { mTiltVector[i] /= Math.PI; mTiltVector[i] *= mTiltSensitivity; if (mTiltVector[i] > 1) { mTiltVector[i] = 1f; } else if (mTiltVector[i] < -1) { mTiltVector[i] = -1f; } } return mTiltVector; }
Example 16
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 17
Source File: OSUtilities.java From Yahala-Messenger with MIT License | 4 votes |
public static void lockOrientation(Activity activity) { if (prevOrientation != -10) { return; } try { prevOrientation = activity.getRequestedOrientation(); WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE); if (manager != null && manager.getDefaultDisplay() != null) { int rotation = manager.getDefaultDisplay().getRotation(); int orientation = activity.getResources().getConfiguration().orientation; if (rotation == Surface.ROTATION_270) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { if (Build.VERSION.SDK_INT >= 9) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } } else if (rotation == Surface.ROTATION_90) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { if (Build.VERSION.SDK_INT >= 9) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else if (rotation == Surface.ROTATION_0) { if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } else { if (orientation == Configuration.ORIENTATION_LANDSCAPE) { if (Build.VERSION.SDK_INT >= 9) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else { if (Build.VERSION.SDK_INT >= 9) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } } } } catch (Exception e) { FileLog.e("yahala", e); } }
Example 18
Source File: CameraConfigurationManager.java From ZXing-Orient with Apache License 2.0 | 4 votes |
void setDesiredCameraParameters(Camera camera, boolean safeMode) { Camera.Parameters parameters = camera.getParameters(); if (parameters == null) { Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration."); return; } Log.i(TAG, "Initial camera parameters: " + parameters.flatten()); if (safeMode) { Log.w(TAG, "In camera config safe mode -- most settings will not be honored"); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); setFlash(camera,parameters, flashSetting); // setAutoFocus(camera, parameters,autoFocusSetting); if (!safeMode) { if (prefs.getBoolean(Preferences.KEY_INVERT_SCAN, false)) { CameraConfigurationUtils.setInvertColor(parameters); } if (!prefs.getBoolean(Preferences.KEY_DISABLE_BARCODE_SCENE_MODE, true)) { CameraConfigurationUtils.setBarcodeSceneMode(parameters); } if (!prefs.getBoolean(Preferences.KEY_DISABLE_METERING, true)) { CameraConfigurationUtils.setVideoStabilization(parameters); CameraConfigurationUtils.setFocusArea(parameters); CameraConfigurationUtils.setMetering(parameters); } } parameters.setPreviewSize(cameraResolution.x, cameraResolution.y); camera.setParameters(parameters); switch (rotation) { case Surface.ROTATION_0: camera.setDisplayOrientation(90); Log.i(TAG,"ROTATION_0 check: "+ rotation); break; case Surface.ROTATION_90: camera.setDisplayOrientation(0); Log.i(TAG,"ROTATION_90 check: "+ rotation); break; case Surface.ROTATION_270: camera.setDisplayOrientation(180); Log.i(TAG,"ROTATION_270 check: "+ rotation); break; default: camera.setDisplayOrientation(0); Log.i(TAG,"Default ROTATION check: "+ rotation); break; } Log.i(TAG,"Rotation Happened"); Camera.Parameters afterParameters = camera.getParameters(); Camera.Size afterSize = afterParameters.getPreviewSize(); if (afterSize!= null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize.height)) { Log.w(TAG, "Camera said it supported preview size " + cameraResolution.x + 'x' + cameraResolution.y + ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height); cameraResolution.x = afterSize.width; cameraResolution.y = afterSize.height; } }
Example 19
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 20
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); }