本文整理匯總了Java中android.hardware.camera2.CameraCharacteristics.LENS_FACING_FRONT屬性的典型用法代碼示例。如果您正苦於以下問題:Java CameraCharacteristics.LENS_FACING_FRONT屬性的具體用法?Java CameraCharacteristics.LENS_FACING_FRONT怎麽用?Java CameraCharacteristics.LENS_FACING_FRONT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.hardware.camera2.CameraCharacteristics
的用法示例。
在下文中一共展示了CameraCharacteristics.LENS_FACING_FRONT屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createCamera
@Override
protected String createCamera(int deviceDegrees) throws CameraException {
try {
for (String camId : mCamManager.getCameraIdList()) {
CameraCharacteristics characteristics = mCamManager.getCameraCharacteristics(camId);
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facing == CameraCharacteristics.LENS_FACING_FRONT) {
Log.d(TAG, "front-facing mCamera found: " + camId);
return camId;
}
}
} catch (CameraAccessException e) {
throw new CameraException(e);
}
throw new CameraException(mActivity.getString(R.string.frontCameraMissing));
}
示例2: sensorToDeviceRotation
/**
* Rotation need to transform from the camera sensor orientation to the device's current
* orientation.
*
* @param c the {@link CameraCharacteristics} to query for the camera sensor
* orientation.
* @param deviceOrientation the current device orientation relative to the native device
* orientation.
* @return the total rotation from the sensor orientation to the current device orientation.
*/
private static int sensorToDeviceRotation(CameraCharacteristics c, int deviceOrientation) {
int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);
// Get device orientation in degrees
deviceOrientation = ORIENTATIONS.get(deviceOrientation);
// Reverse device orientation for front-facing cameras
if (c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
deviceOrientation = -deviceOrientation;
}
// Calculate desired JPEG orientation relative to camera orientation to make
// the image upright relative to the device orientation
return (sensorOrientation + deviceOrientation + 360) % 360;
}
示例3: sensorToDeviceRotation
/**
* Rotation need to transform from the camera sensor orientation to the device's current
* orientation.
*
* @param c the {@link CameraCharacteristics} to query for the camera sensor
* orientation.
* @param deviceOrientation the current device orientation relative to the native device
* orientation.
* @return the total rotation from the sensor orientation to the current device orientation.
*/
public static int sensorToDeviceRotation(CameraCharacteristics c, int deviceOrientation) {
int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);
// Get device orientation in degrees
deviceOrientation = ORIENTATIONS.get(deviceOrientation);
// Reverse device orientation for front-facing cameras
if (c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
deviceOrientation = -deviceOrientation;
}
// Calculate desired JPEG orientation relative to camera orientation to make
// the image upright relative to the device orientation
return (sensorOrientation + deviceOrientation + 360) % 360;
}
示例4: toggleFacing
public void toggleFacing() {
if (facingSelected == CameraCharacteristics.LENS_FACING_FRONT) {
facingSelected = CameraCharacteristics.LENS_FACING_BACK;
toggleButton.setImageResource(R.drawable.ic_camera_rear);
} else {
facingSelected = CameraCharacteristics.LENS_FACING_FRONT;
toggleButton.setImageResource(R.drawable.ic_camera_front);
}
toggleButton.invalidate();
closeCamera();
if (textureView.isAvailable()) {
openCamera(textureView.getWidth(), textureView.getHeight());
} else {
textureView.setSurfaceTextureListener(surfaceTextureListener);
}
}
示例5: initializeCameraManager
@Override
public void initializeCameraManager(ConfigurationProvider configurationProvider, Context context) {
super.initializeCameraManager(configurationProvider, context);
this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
final Display display = windowManager.getDefaultDisplay();
final Point size = new Point();
display.getSize(size);
windowSize = new Size(size.x, size.y);
try {
final String[] ids = manager.getCameraIdList();
numberOfCameras = ids.length;
for (String id : ids) {
final CameraCharacteristics characteristics = manager.getCameraCharacteristics(id);
final int orientation = characteristics.get(CameraCharacteristics.LENS_FACING);
if (orientation == CameraCharacteristics.LENS_FACING_FRONT) {
faceFrontCameraId = id;
faceFrontCameraOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
frontCameraCharacteristics = characteristics;
} else {
faceBackCameraId = id;
faceBackCameraOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
backCameraCharacteristics = characteristics;
}
}
} catch (Exception e) {
Log.e(TAG, "Error during camera init");
}
}
示例6: chooseCamera
private String chooseCamera() {
final CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
for (final String cameraId : manager.getCameraIdList()) {
final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
// We don't use a front facing camera in this sample.
final Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
continue;
}
final StreamConfigurationMap map =
characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
if (map == null) {
continue;
}
useCamera2API = isHardwareLevelSupported(characteristics,
CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL);
LOGGER.i("Camera API lv2?: %s", useCamera2API);
return cameraId;
}
} catch (CameraAccessException e) {
LOGGER.e(e, "Not allowed to access camera");
}
return null;
}
示例7: getCameraId
private String getCameraId() throws CameraAccessException {
int camera = frontFacingCameraActive ? CameraCharacteristics.LENS_FACING_FRONT
: CameraCharacteristics.LENS_FACING_BACK;
for (String cameraId : cameraManager.getCameraIdList()) {
CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING)
== camera) {
return cameraId;
}
}
return null;
}
示例8: getFrontFacingCameraId
@Nullable
private String getFrontFacingCameraId() throws CameraAccessException {
for (String cameraId : manager.getCameraIdList()) {
try {
if (cameraCharacteristicsHelper.getLensFacing(cameraId) == CameraCharacteristics.LENS_FACING_FRONT) {
return cameraId;
}
} catch (CameraException e) {
// could not determine lens facing characteristic -> continue
}
}
return null;
}
示例9: getCameraResolutionsFront
public Size[] getCameraResolutionsFront() {
try {
CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics("0");
if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING)
!= CameraCharacteristics.LENS_FACING_FRONT) {
cameraCharacteristics = cameraManager.getCameraCharacteristics("1");
}
StreamConfigurationMap streamConfigurationMap =
cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
return streamConfigurationMap.getOutputSizes(SurfaceTexture.class);
} catch (CameraAccessException e) {
Log.e(TAG, e.getMessage());
return new Size[0];
}
}
示例10: toggleCamera
private void toggleCamera() {
Integer lens = mCamera.getCurrentLensFacing();
switch (lens) {
case CameraCharacteristics.LENS_FACING_FRONT:
mCamera.openCamera(CameraCharacteristics.LENS_FACING_BACK);
break;
case CameraCharacteristics.LENS_FACING_BACK:
mCamera.openCamera(CameraCharacteristics.LENS_FACING_FRONT);
break;
}
}
示例11: initCameraAndPreview
private void initCameraAndPreview() {
Log.i(TAG, "initCameraAndPreview: is called");
HandlerThread handlerThread = new HandlerThread("Camera2");
handlerThread.start();
mHandler = new Handler(handlerThread.getLooper());
mCameraId = CameraCharacteristics.LENS_FACING_FRONT + "";
mImageReader = ImageReader.newInstance(
mSurfaceView.getWidth(),
mSurfaceView.getHeight(),
ImageFormat.JPEG,
7 /* maxImages */
);
mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
}
}, mHandler);
RequestPermissions.requestRuntimePermission(
getActivity(),
new String[]{Manifest.permission.CAMERA},
new RequestPermissions.OnRequestPermissionsListener() {
@Override
public void onGranted() {
try {
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
return;
}
mCameraManager.openCamera(mCameraId, deviceStateCallback, mHandler);
} catch (CameraAccessException e) {
Log.e(TAG, "initCameraAndPreview: open camera failed", e);
}
}
@Override
public void onDenied(List<String> deniedPermission) {
}
});
}