android.hardware.Camera.CameraInfo Java Examples
The following examples show how to use
android.hardware.Camera.CameraInfo.
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: CameraUtils.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
public static int getCameraDisplayOrientation(@NonNull Activity activity, @NonNull CameraInfo info) { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; DisplayMetrics dm = new DisplayMetrics(); activity.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; } if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { return (360 - ((info.orientation + degrees) % 360)) % 360; } else { return (info.orientation - degrees + 360) % 360; } }
Example #2
Source File: CameraSurfaceView.java From Paddle-Lite-Demo with Apache License 2.0 | 6 votes |
public CameraSurfaceView(Context ctx, AttributeSet attrs) { super(ctx, attrs); context = ctx; setEGLContextClientVersion(2); setRenderer(this); setRenderMode(RENDERMODE_WHEN_DIRTY); // Find the total number of available cameras and the ID of the default camera numberOfCameras = Camera.getNumberOfCameras(); CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < numberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { selectedCameraId = i; } } }
Example #3
Source File: CameraSurfaceView.java From Paddle-Lite-Demo with Apache License 2.0 | 6 votes |
public CameraSurfaceView(Context ctx, AttributeSet attrs) { super(ctx, attrs); context = ctx; setEGLContextClientVersion(2); setRenderer(this); setRenderMode(RENDERMODE_WHEN_DIRTY); // Find the total number of available cameras and the ID of the default camera numberOfCameras = Camera.getNumberOfCameras(); CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < numberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { selectedCameraId = i; } } }
Example #4
Source File: CameraSurfaceView.java From Paddle-Lite-Demo with Apache License 2.0 | 6 votes |
public CameraSurfaceView(Context ctx, AttributeSet attrs) { super(ctx, attrs); context = ctx; setEGLContextClientVersion(2); setRenderer(this); setRenderMode(RENDERMODE_WHEN_DIRTY); // Find the total number of available cameras and the ID of the default camera numberOfCameras = Camera.getNumberOfCameras(); CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < numberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { selectedCameraId = i; } } }
Example #5
Source File: FURenderer.java From sealrtc-android with MIT License | 6 votes |
private int calculateRotModeLagacy() { int mode; if (mInputOrientation == 270) { if (mCameraFacing == Camera.CameraInfo.CAMERA_FACING_FRONT) { mode = mDeviceOrientation / 90; } else { mode = (mDeviceOrientation - 180) / 90; } } else { if (mCameraFacing == Camera.CameraInfo.CAMERA_FACING_FRONT) { mode = (mDeviceOrientation + 180) / 90; } else { mode = mDeviceOrientation / 90; } } return mode; }
Example #6
Source File: CameraSurfaceView.java From Paddle-Lite-Demo with Apache License 2.0 | 6 votes |
public CameraSurfaceView(Context ctx, AttributeSet attrs) { super(ctx, attrs); context = ctx; setEGLContextClientVersion(2); setRenderer(this); setRenderMode(RENDERMODE_WHEN_DIRTY); // Find the total number of available cameras and the ID of the default camera numberOfCameras = Camera.getNumberOfCameras(); CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < numberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { selectedCameraId = i; } } }
Example #7
Source File: CameraSurfaceView.java From Paddle-Lite-Demo with Apache License 2.0 | 6 votes |
public CameraSurfaceView(Context ctx, AttributeSet attrs) { super(ctx, attrs); context = ctx; setEGLContextClientVersion(2); setRenderer(this); setRenderMode(RENDERMODE_WHEN_DIRTY); // Find the total number of available cameras and the ID of the default camera numberOfCameras = Camera.getNumberOfCameras(); CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < numberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { selectedCameraId = i; } } }
Example #8
Source File: CameraManager.java From green_android with GNU General Public License v3.0 | 6 votes |
private int determineCameraId() { final int cameraCount = Camera.getNumberOfCameras(); final CameraInfo cameraInfo = new CameraInfo(); // prefer back-facing camera for (int i = 0; i < cameraCount; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) return i; } // fall back to front-facing camera for (int i = 0; i < cameraCount; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) return i; } return -1; }
Example #9
Source File: SurfaceGrabberActivity.java From zom-android-matrix with Apache License 2.0 | 6 votes |
private boolean tryCreateCamera(int facing) { CameraInfo info = new CameraInfo(); for (int nCam = 0; nCam < Camera.getNumberOfCameras(); nCam++) { Camera.getCameraInfo(nCam, info); if (info.facing == facing) { camera = Camera.open(nCam); cameraInfo = info; //Size size = choosePictureSize(camera.getParameters().getSupportedPictureSizes()); Camera.Parameters params = camera.getParameters(); params.setPictureFormat(ImageFormat.JPEG); //params.setPictureSize(size.width,size.height); //params.setJpegThumbnailSize(128,128); //params.setPreviewSize(size.width/2,size.height/2); if (this.getCameraDirection() == CameraInfo.CAMERA_FACING_BACK) { params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); } camera.setParameters(params); return true; } } return false; }
Example #10
Source File: LegacyMetadataMapper.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Create characteristics for a legacy device by mapping the {@code parameters} * and {@code info} * * @param parameters A string parseable by {@link Camera.Parameters#unflatten} * @param info Camera info with camera facing direction and angle of orientation * @return static camera characteristics for a camera device * * @throws NullPointerException if any of the args were {@code null} */ public static CameraCharacteristics createCharacteristics(String parameters, android.hardware.CameraInfo info) { checkNotNull(parameters, "parameters must not be null"); checkNotNull(info, "info must not be null"); checkNotNull(info.info, "info.info must not be null"); CameraMetadataNative m = new CameraMetadataNative(); mapCharacteristicsFromInfo(m, info.info); Camera.Parameters params = Camera.getEmptyParameters(); params.unflatten(parameters); mapCharacteristicsFromParameters(m, params); if (DEBUG) { Log.v(TAG, "createCharacteristics metadata:"); Log.v(TAG, "--------------------------------------------------- (start)"); m.dumpToLog(); Log.v(TAG, "--------------------------------------------------- (end)"); } return new CameraCharacteristics(m); }
Example #11
Source File: FURenderer.java From sealrtc-android with MIT License | 6 votes |
/** * 双输入接口(fuDualInputToTexture)(处理后的画面数据并不会回写到数组),由于省去相应的数据拷贝性能相对最优,推荐使用。 * * @param img NV21数据 * @param tex 纹理ID * @param w * @param h * @return */ public int onDrawFrame(byte[] img, int tex, int w, int h) { if (tex <= 0 || img == null || w <= 0 || h <= 0) { Log.e(TAG, "onDrawFrame data null"); return 0; } prepareDrawFrame(); int flags = mInputTextureType | mInputImageFormat; if (mCameraFacing != Camera.CameraInfo.CAMERA_FACING_FRONT) flags |= FU_ADM_FLAG_FLIP_X; if (mNeedBenchmark) mFuCallStartTime = System.nanoTime(); int fuTex = faceunity.fuDualInputToTexture(img, tex, flags, w, h, mFrameId++, mItemsArray); if (mNeedBenchmark) mOneHundredFrameFUTime += System.nanoTime() - mFuCallStartTime; return fuTex; }
Example #12
Source File: FURenderer.java From sealrtc-android with MIT License | 6 votes |
/** * 单输入接口(fuRenderToNV21Image) * * @param img NV21数据 * @param w * @param h * @return */ public int onDrawFrame(byte[] img, int w, int h) { if (img == null || w <= 0 || h <= 0) { Log.e(TAG, "onDrawFrame data null"); return 0; } prepareDrawFrame(); int flags = mInputImageFormat; if (mCameraFacing != Camera.CameraInfo.CAMERA_FACING_FRONT) flags |= FU_ADM_FLAG_FLIP_X; if (mNeedBenchmark) mFuCallStartTime = System.nanoTime(); int fuTex = faceunity.fuRenderToNV21Image(img, w, h, mFrameId++, mItemsArray, flags); if (mNeedBenchmark) mOneHundredFrameFUTime += System.nanoTime() - mFuCallStartTime; return fuTex; }
Example #13
Source File: FURenderer.java From sealrtc-android with MIT License | 6 votes |
/** * 获取相机方向 * * @param cameraFacing * @return */ public static int getCameraOrientation(int cameraFacing) { Camera.CameraInfo info = new Camera.CameraInfo(); int cameraId = -1; int numCameras = Camera.getNumberOfCameras(); for (int i = 0; i < numCameras; i++) { Camera.getCameraInfo(i, info); if (info.facing == cameraFacing) { cameraId = i; break; } } if (cameraId < 0) { // no front camera, regard it as back camera return 90; } else { return info.orientation; } }
Example #14
Source File: CameraEngine.java From TikTok with Apache License 2.0 | 6 votes |
public static com.tiktokdemo.lky.tiktokdemo.record.camera.camera.utils.CameraInfo getCameraInfo(){ com.tiktokdemo.lky.tiktokdemo.record.camera.camera.utils.CameraInfo info = new com.tiktokdemo.lky.tiktokdemo.record.camera.camera.utils.CameraInfo(); try{ Size size = getPreviewSize(); CameraInfo cameraInfo = new CameraInfo(); mCameraInfo = cameraInfo; Camera.getCameraInfo(cameraID, cameraInfo); info.previewWidth = PREVIEW_WIDTH; info.previewHeight = PREVIEW_HEIGHT; info.orientation = cameraInfo.orientation; info.isFront = cameraID == 1 ? true : false; size = getPictureSize(); if (size != null){ info.pictureWidth = size.width; info.pictureHeight = size.height; } if(camera != null){ info.flashMode = camera.getParameters().getFlashMode(); } return info; }catch (Exception e){ e.printStackTrace(); return info; } }
Example #15
Source File: CameraManager.java From bcm-android with GNU General Public License v3.0 | 6 votes |
private int determineCameraId() { final int cameraCount = Camera.getNumberOfCameras(); final CameraInfo cameraInfo = new CameraInfo(); // prefer back-facing camera for (int i = 0; i < cameraCount; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { return i; } } // fall back to front-facing camera for (int i = 0; i < cameraCount; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { return i; } } return -1; }
Example #16
Source File: PreMarshmallow.java From lantern with Apache License 2.0 | 5 votes |
private int getCameraId() { int numberOfCameras = Camera.getNumberOfCameras(); for (int i = 0; i < numberOfCameras; i++) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(i, info); if (info.facing == CameraInfo.CAMERA_FACING_BACK) { return i; } } return 0; }
Example #17
Source File: CameraOverlapFragment.java From Fatigue-Detection with MIT License | 5 votes |
private void openCamera(int CameraFacing){ if (null != mCamera) { mCamera.setPreviewCallback(null); mCamera.stopPreview(); mCamera.release(); mCamera = null; } CameraInfo info = new CameraInfo(); for(int i = 0; i < Camera.getNumberOfCameras(); i++) { Camera.getCameraInfo(i, info); if(info.facing == CameraFacing) { try{ mCamera = Camera.open(i); mCameraInfo = info; } catch(RuntimeException e) { e.printStackTrace(); mCamera = null; continue; } break; } } try { Log.i(TAG, "SurfaceHolder.Callback?surface Created"); mCamera.setPreviewDisplay(mSurfaceHolder);// set the surface to be used for live preview initCamera(); } catch (Exception ex) { if (null != mCamera) { mCamera.release(); mCamera = null; } // Log.i(TAG + "initCamera", ex.getMessage()); } }
Example #18
Source File: CameraSource.java From Camera2Vision with Apache License 2.0 | 5 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; switch (windowManager.getDefaultDisplay().getRotation()) { 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"); } CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int angle; int displayAngle; if (cameraInfo.facing == Camera.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 #19
Source File: CameraSource.java From Machine-Learning-Projects-for-Mobile-Applications with MIT License | 5 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; switch (windowManager.getDefaultDisplay().getRotation()) { 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"); } CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int angle; int displayAngle; if (cameraInfo.facing == Camera.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 Machine-Learning-Projects-for-Mobile-Applications with MIT License | 5 votes |
/** * Gets the id for the camera specified by the direction it is facing. Returns -1 if no such * camera was found. * * @param facing the desired camera (front-facing or rear-facing) */ private static int getIdForRequestedCamera(int facing) { CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == facing) { return i; } } return -1; }
Example #21
Source File: LegacyCameraConnectionFragment.java From dbclf with Apache License 2.0 | 5 votes |
private int getCameraId() { CameraInfo ci = new CameraInfo(); for (int i = 0; i < Camera.getNumberOfCameras(); i++) { Camera.getCameraInfo(i, ci); if (ci.facing == CameraInfo.CAMERA_FACING_BACK) return i; } return -1; // No camera found }
Example #22
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 #23
Source File: CameraSource.java From OCR-Reader with MIT License | 5 votes |
/** * Gets the id for the camera specified by the direction it is facing. Returns -1 if no such * camera was found. * * @param facing the desired camera (front-facing or rear-facing) */ private static int getIdForRequestedCamera(int facing) { CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == facing) { return i; } } return -1; }
Example #24
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 #25
Source File: FURenderer.java From sealrtc-android with MIT License | 5 votes |
/** * 计算 RotationMode 相机方向和 RotationMode 参数对照: - 前置 270:home 下 1,home 右 0,home 上 3,home 左 2 - 后置 * 90: home 下 3,home 右 0,home 上 1,home 左 2 */ private int calculateRotationMode() { int rotMode = faceunity.FU_ROTATION_MODE_0; if (mInputOrientation == 270) { if (mCameraFacing == Camera.CameraInfo.CAMERA_FACING_FRONT) { rotMode = mDeviceOrientation / 90; } else { if (mDeviceOrientation == 90) { rotMode = faceunity.FU_ROTATION_MODE_270; } else if (mDeviceOrientation == 270) { rotMode = faceunity.FU_ROTATION_MODE_90; } else { rotMode = mDeviceOrientation / 90; } } } else if (mInputOrientation == 90) { if (mCameraFacing == Camera.CameraInfo.CAMERA_FACING_BACK) { if (mDeviceOrientation == 90) { rotMode = faceunity.FU_ROTATION_MODE_270; } else if (mDeviceOrientation == 270) { rotMode = faceunity.FU_ROTATION_MODE_90; } else { rotMode = mDeviceOrientation / 90; } } else { if (mDeviceOrientation == 0) { rotMode = faceunity.FU_ROTATION_MODE_180; } else if (mDeviceOrientation == 90) { rotMode = faceunity.FU_ROTATION_MODE_270; } else if (mDeviceOrientation == 180) { rotMode = faceunity.FU_ROTATION_MODE_0; } else { rotMode = faceunity.FU_ROTATION_MODE_90; } } } return rotMode; }
Example #26
Source File: ICamera.java From MegviiFacepp-Android-SDK with Apache License 2.0 | 5 votes |
/** * 打开相机 */ public Camera openCamera(boolean isBackCamera, Activity activity, HashMap<String, Integer> resolutionMap) { try { if (isBackCamera) cameraId = 0; else cameraId = 1; int width = 640; int height = 480; if (resolutionMap != null) { width = resolutionMap.get("width"); height = resolutionMap.get("height"); } mCamera = Camera.open(cameraId); CameraInfo cameraInfo = new CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); Camera.Parameters params = mCamera.getParameters(); // Camera.Size bestPreviewSize = calBestPreviewSize( // mCamera.getParameters(), Screen.mWidth, Screen.mHeight); Camera.Size bestPreviewSize = calBestPreviewSize( mCamera.getParameters(), width, height); cameraWidth = bestPreviewSize.width; cameraHeight = bestPreviewSize.height; params.setPreviewSize(cameraWidth, cameraHeight); Angle = getCameraAngle(activity); Log.w("ceshi", "Angle==" + Angle); Log.d("ceshi", "width = " + cameraWidth + ", height = " + cameraHeight); // mCamera.setDisplayOrientation(Angle); mCamera.setParameters(params); return mCamera; } catch (Exception e) { e.printStackTrace(); return null; } }
Example #27
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 #28
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 #29
Source File: Camera1Controller.java From pixelvisualcorecamera with Apache License 2.0 | 5 votes |
/** * Configures camera parameters common to all configurations. * Must be called before preview started. */ public void setDefaultParameters(int displayRotation) { Log.i(TAG, "setDefaultParameters"); assertState(STATE_ACQUIRED, "Default parameters may only be set before a preview is started"); CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); boolean lensFacingFront = (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT); int previewOrientationDegrees = Orientation.getPreviewOrientation(lensFacingFront, displayRotation, info.orientation); camera.setDisplayOrientation(previewOrientationDegrees); Parameters params = camera.getParameters(); // We happen to know the preview sizes available for Pixel 2. params.setPreviewSize(Utils.MAX_PREVIEW_WIDTH, Utils.MAX_PREVIEW_HEIGHT); params.setRotation( Orientation.getOutputOrientation(lensFacingFront, displayRotation, info.orientation)); // Continuous picture is not supported Pixel 2's front camera. List<String> supportFocusModes = params.getSupportedFocusModes(); if (supportFocusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { Log.i(TAG, "setting continuous picture focus mode"); params.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } // HDR+: Flash mode must be off. params.setFlashMode(Parameters.FLASH_MODE_OFF); // HDR+: Color effect must be none. params.setColorEffect(Parameters.EFFECT_NONE); // HDR+: White balance must be auto. params.setWhiteBalance(Parameters.WHITE_BALANCE_AUTO); camera.setParameters(params); }
Example #30
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; }