本文整理汇总了Java中android.hardware.camera2.CameraCharacteristics类的典型用法代码示例。如果您正苦于以下问题:Java CameraCharacteristics类的具体用法?Java CameraCharacteristics怎么用?Java CameraCharacteristics使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CameraCharacteristics类属于android.hardware.camera2包,在下文中一共展示了CameraCharacteristics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collectCameraInfo
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
/**
* <p>Collects some information from {@link #mCameraCharacteristics}.</p>
* <p>This rewrites {@link #mPreviewSizes}, {@link #mPictureSizes}, and optionally,
* {@link #mAspectRatio}.</p>
*/
private void collectCameraInfo() {
StreamConfigurationMap map = mCameraCharacteristics.get(
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
if (map == null) {
throw new IllegalStateException("Failed to get configuration map: " + mCameraId);
}
mPreviewSizes.clear();
for (android.util.Size size : map.getOutputSizes(mPreview.getOutputClass())) {
mPreviewSizes.add(new Size(size.getWidth(), size.getHeight()));
}
mPictureSizes.clear();
collectPictureSizes(mPictureSizes, map);
if (!mPreviewSizes.ratios().contains(mAspectRatio)) {
mAspectRatio = mPreviewSizes.ratios().iterator().next();
}
}
示例2: onCreate
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_v2);
CameraManager cameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
try {
for (String cameraId : cameraManager.getCameraIdList()) {
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facing != null && facing.equals(CameraCharacteristics.LENS_FACING_FRONT)) {
}
// Do something with the characteristics
}
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例3: onStopTrackingTouch
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
switch (seekBar.getId()) {
case R.id.iso: {
Range<Integer> range = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_SENSITIVITY_RANGE);
int max = range.getUpper();
int min = range.getLower();
isoValue = ((seekBar.getProgress() * (max - min)) / 100 + min);
createCameraPreviewSession_ISO();
break;
}
case R.id.focus: {
float distance = mCameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
focusValue = seekBar.getProgress() * distance / 100;
createCameraPreviewSession_FOCUS();
break;
}
default:
break;
}
}
示例4: logSupportedHardwareLevel
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
private void logSupportedHardwareLevel(@NonNull String cameraId) {
int hardwareLevel = cameraCharacteristicsHelper.getSupportedHardwareLevel(cameraId);
String hardwareLevelName = String.valueOf(hardwareLevel); // for level 3 and higher
switch (hardwareLevel) {
case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY:
hardwareLevelName = "legacy";
break;
case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED:
hardwareLevelName = "limited";
break;
case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL:
hardwareLevelName = "full";
break;
}
log.d("using camera with supported hardware level: %s", hardwareLevelName);
}
示例5: open
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
public void open() {
try {
CameraManager manager = (CameraManager) mActivity.getSystemService(Context.CAMERA_SERVICE);
for (String cameraId : manager.getCameraIdList()) {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
if (characteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_BACK) {
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
mCameraSize = map.getOutputSizes(SurfaceTexture.class)[0];
HandlerThread thread = new HandlerThread("OpenCamera");
thread.start();
Handler backgroundHandler = new Handler(thread.getLooper());
manager.openCamera(cameraId, mCameraDeviceCallback, null);
// カメラの物理的な情報を得る
mCameraCharacteristics = manager.getCameraCharacteristics( cameraId );
return;
}
}
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例6: updateAutoFocus
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
/**
* Updates the internal state of auto-focus to {@link #mAutoFocus}.
*/
void updateAutoFocus() {
if (mAutoFocus) {
int[] modes = mCameraCharacteristics.get(
CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
// Auto focus is not supported
if (modes == null || modes.length == 0 ||
(modes.length == 1 && modes[0] == CameraCharacteristics.CONTROL_AF_MODE_OFF)) {
mAutoFocus = false;
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_OFF);
} else {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
}
} else {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_OFF);
}
}
示例7: needSwappedDimensions
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
/**
* Find out if we need to swap dimensions to get the preview size relative to sensor coordinate.
* @param activity - The associated activity from which the camera is loaded.
* @param characteristics - CameraCharacteristics corresponding to the current started cameradevice
* @return swappedDimensions - A boolean value indicating if the the dimensions need to be swapped.
*/
public static boolean needSwappedDimensions(Activity activity, CameraCharacteristics characteristics) {
int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
//noinspection ConstantConditions
int mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
boolean swappedDimensions = false;
switch (displayRotation) {
case Surface.ROTATION_0:
case Surface.ROTATION_90:
if (mSensorOrientation == 90 || mSensorOrientation == 270) {
swappedDimensions = true;
}
break;
case Surface.ROTATION_180:
case Surface.ROTATION_270:
if (mSensorOrientation == 0 || mSensorOrientation == 180) {
swappedDimensions = true;
}
break;
default:
Log.e(TAG, "Display rotation is invalid: " + displayRotation);
}
return swappedDimensions;
}
示例8: createCamera
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
@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));
}
示例9: getCameraInfo
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
@Override
protected String getCameraInfo() {
String camStr = mContext.getString(R.string.camApi2) + "\n";
CameraManager camManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
try {
for (String camId : camManager.getCameraIdList()) {
camStr += mContext.getString(R.string.cameraId, camId) + ": ";
CameraCharacteristics characteristics = camManager.getCameraCharacteristics(camId);
Boolean hasFlash = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
camStr += (hasFlash ? mContext.getString(R.string.has) : mContext.getString(R.string.no))
+ " " + mContext.getString(R.string.flash) + ", ";
camStr += (facing == CameraCharacteristics.LENS_FACING_BACK ?
mContext.getString(R.string.backFacing) : mContext.getString(R.string.frontFacing)) + "\n";
}
} catch (CameraAccessException e) {
camStr = mActivity.getString(R.string.failedAccessCamera) + ":" + e.getMessage();
}
return camStr.trim();
}
示例10: FlashController
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
public FlashController(Context ctx, CameraManager cameraManager, ServerConnection serverConnection) throws CameraAccessException, IllegalAccessException {
mCtx = ctx;
camManager = cameraManager;
mServerConnection = serverConnection;
EventBus.getDefault().register(this);
for (String camId : camManager.getCameraIdList()) {
CameraCharacteristics characteristics = camManager.getCameraCharacteristics(camId);
Boolean hasFlash = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facing == CameraCharacteristics.LENS_FACING_BACK && hasFlash) {
torchId = camId;
break;
}
}
if (torchId == null) {
throw new IllegalAccessException(ctx.getString(R.string.couldNotFindBackFlash));
}
}
示例11: collectRatioSizes
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
@Override
public void collectRatioSizes() {
ratioSizeList.clear();
CameraCharacteristics characteristics;
StreamConfigurationMap map = null;
try {
characteristics = ((CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE)).getCameraCharacteristics(Integer.toString(Integer.parseInt(getCameraId())));
map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
} catch (CameraAccessException e) {
e.printStackTrace();
}
Size[] outputSizes = map.getOutputSizes(SurfaceTexture.class);
if (outputSizes != null) {
List<Double> ratioList = new ArrayList<>();
for (Size size : outputSizes) {
double ratio = (double) size.getWidth() / (double) size.getHeight();
if (!ratioList.contains(ratio)) {
ratioList.add(ratio);
ratioSizeList.add(new AspectRatio(ratio, size.getWidth(), size.getHeight()));
}
}
}
}
示例12: sensorToDeviceRotation
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
/**
* 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;
}
示例13: getOrThrow
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
@NonNull
private <T> T getOrThrow(@NonNull String cameraId, @NonNull CameraCharacteristics.Key<T> key) {
try {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
T value = characteristics.get(key);
if (value == null) {
throw new CameraException("could not determine camera characteristic " + key.getName() + " from camera " + cameraId);
} else {
return value;
}
} catch (CameraAccessException e) {
throw new CameraException(e);
}
}
示例14: setUp
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
surfaces = asList(surface1, surface2);
when(manager.getCameraIdList()).thenReturn(new String[]{CAMERA_ID_1, CAMERA_ID_2});
when(characteristicsHelper.getLensFacing(CAMERA_ID_1)).thenReturn(CameraCharacteristics.LENS_FACING_BACK);
when(characteristicsHelper.getLensFacing(CAMERA_ID_2)).thenReturn(CameraCharacteristics.LENS_FACING_FRONT);
when(characteristicsHelper.getSensorOrientation(CAMERA_ID_1)).thenReturn(SENSOR_ROTATION);
when(characteristicsHelper.getPreviewOutputSizes(CAMERA_ID_1)).thenReturn(
new Size[]{PREVIEWSIZE_1, PREVIEWSIZE_640x480, PREVIEWSIZE_2});
when(camera.getId()).thenReturn(CAMERA_ID_1);
when(camera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)).thenReturn(captureRequestBuilder);
when(textureView.getSurfaceTexture()).thenReturn(surfaceTexture);
}
示例15: sensorToDeviceRotation
import android.hardware.camera2.CameraCharacteristics; //导入依赖的package包/类
/**
* 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;
}