List of usage examples for android.hardware.camera2 CameraCharacteristics get
@Nullable
public <T> T get(Key<T> key)
From source file:Main.java
/** * Calculates sensor crop region for a zoom level (zoom >= 1.0). * * @return Crop region./*from w w w.jav a 2s . com*/ */ public static Rect cropRegionForZoom(CameraCharacteristics characteristics, float zoom) { Rect sensor = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); int xCenter = sensor.width() / 2; int yCenter = sensor.height() / 2; int xDelta = (int) (0.5f * sensor.width() / zoom); int yDelta = (int) (0.5f * sensor.height() / zoom); return new Rect(xCenter - xDelta, yCenter - yDelta, xCenter + xDelta, yCenter + yDelta); }
From source file:Main.java
public static int getJPEGOrientation(int rotation, CameraCharacteristics cameraCharacteristics) { Integer sensorOrientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); sensorOrientation = sensorOrientation == null ? 0 : sensorOrientation; // Sensor orientation is 90 for most devices, or 270 for some devices (eg. Nexus 5X) // We have to take that into account and rotate JPEG properly. // For devices with orientation of 90, we simply return our mapping from ORIENTATIONS. // For devices with orientation of 270, we need to rotate the JPEG 180 degrees. return (ORIENTATIONS.get(rotation) + sensorOrientation + 270) % 360; }
From source file:Main.java
/** * Returns {@code true} if this device only supports {@code LEGACY} mode operation in the * Camera2 API for the given camera ID./*from w ww .j a v a2 s .c o m*/ * * @param context {@link Context} to access the {@link CameraManager} in. * @param cameraId the ID of the camera device to check. * @return {@code true} if this device only supports {@code LEGACY} mode. */ public static boolean isLegacyHAL(Context context, int cameraId) throws Exception { CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); CameraCharacteristics characteristics = manager.getCameraCharacteristics(Integer.toString(cameraId)); return characteristics.get( CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY; }
From source file:Main.java
public static int getJpegOrientation(CameraCharacteristics c, int deviceOrientation) { if (deviceOrientation == android.view.OrientationEventListener.ORIENTATION_UNKNOWN) return 0; int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION); // Round device orientation to a multiple of 90 deviceOrientation = (deviceOrientation + 45) / 90 * 90; // Reverse device orientation for front-facing cameras boolean facingFront = c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT; if (facingFront) deviceOrientation = -deviceOrientation; // Calculate desired JPEG orientation relative to camera orientation to make // the image upright relative to the device orientation int jpegOrientation = (sensorOrientation + deviceOrientation + 360) % 360; return jpegOrientation; }
From source file:com.android.camera2.its.ItsUtils.java
private static Size[] getOutputSizes(CameraCharacteristics ccs, int format) throws ItsException { StreamConfigurationMap configMap = ccs.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (configMap == null) { throw new ItsException("Failed to get stream config"); }/*from ww w .j av a2 s . c o m*/ return configMap.getOutputSizes(format); }
From source file:com.google.android.apps.watchme.StreamerActivity.java
private static int sensorToDeeviceRotation(CameraCharacteristics cameraCharacteristics, int deviceOrientation) { int sensorOrientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); deviceOrientation = ORIENTATIONS.get(deviceOrientation); return (sensorOrientation + deviceOrientation + 360) % 360; }
From source file:com.android.camera.one.v2.OneCameraZslImpl.java
/** * Calculate the aspect ratio of the full size capture on this device. * * @param characteristics the characteristics of the camera device. * @return The aspect ration, in terms of width/height of the full capture * size./*from ww w . j av a 2 s. co m*/ */ private static float calculateFullSizeAspectRatio(CameraCharacteristics characteristics) { Rect activeArraySize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); return ((float) activeArraySize.width()) / activeArraySize.height(); }
From source file:MainActivity.java
private String getCameraId() { try {/*from w ww .j ava 2 s. co m*/ String[] ids = mCameraManager.getCameraIdList(); for (String id : ids) { CameraCharacteristics c = mCameraManager.getCameraCharacteristics(id); Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); Integer facingDirection = c.get(CameraCharacteristics.LENS_FACING); if (flashAvailable != null && flashAvailable && facingDirection != null && facingDirection == CameraCharacteristics.LENS_FACING_BACK) { return id; } } } catch (CameraAccessException e) { e.printStackTrace(); } return null; }
From source file:com.elkriefy.android.apps.torchi.MainActivity.java
private void toggleTorchMode() { try {// w ww . j a v a 2 s.c om String[] cameraIdList = manager.getCameraIdList(); CameraCharacteristics cameraCharacteristics = manager.getCameraCharacteristics(cameraIdList[0]); if (cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)) { torchMode = !torchMode; manager.setTorchMode(cameraIdList[0], torchMode); } else { CameraCharacteristics cameraCharacteristics1 = manager.getCameraCharacteristics(cameraIdList[1]); if (cameraCharacteristics1.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)) { torchMode = !torchMode; manager.setTorchMode(cameraIdList[1], torchMode); } } } catch (Exception err) { err.printStackTrace(); } }
From source file:MainActivity.java
private void openCamera() { CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE); try {//from ww w.ja v a 2s . com String cameraId = manager.getCameraIdList()[0]; CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); mPreviewSize = map.getOutputSizes(SurfaceTexture.class)[0]; manager.openCamera(cameraId, mStateCallback, null); } catch (CameraAccessException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } }