本文整理汇总了Java中android.hardware.camera2.CameraCharacteristics.get方法的典型用法代码示例。如果您正苦于以下问题:Java CameraCharacteristics.get方法的具体用法?Java CameraCharacteristics.get怎么用?Java CameraCharacteristics.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.hardware.camera2.CameraCharacteristics
的用法示例。
在下文中一共展示了CameraCharacteristics.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: isSupported
import android.hardware.camera2.CameraCharacteristics; //导入方法依赖的package包/类
/**
* Checks if API is supported and all cameras have better than legacy support.
*/
public static boolean isSupported(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return false;
}
CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
try {
String[] cameraIds = cameraManager.getCameraIdList();
for (String id : cameraIds) {
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(id);
if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)
== CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
return false;
}
}
// On Android OS pre 4.4.2, a class will not load because of VerifyError if it contains a
// catch statement with an Exception from a newer API, even if the code is never executed.
// https://code.google.com/p/android/issues/detail?id=209129
} catch (/* CameraAccessException */ AndroidException e) {
Logging.e(TAG, "Camera access exception: " + e);
return false;
}
return true;
}
示例3: 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;
}
示例4: 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);
}
}
示例5: isBackFacing
import android.hardware.camera2.CameraCharacteristics; //导入方法依赖的package包/类
@Override
public boolean isBackFacing(String deviceName) {
CameraCharacteristics characteristics = getCameraCharacteristics(deviceName);
return characteristics != null
&& characteristics.get(CameraCharacteristics.LENS_FACING)
== CameraMetadata.LENS_FACING_BACK;
}
示例6: isHardwareLevelSupported
import android.hardware.camera2.CameraCharacteristics; //导入方法依赖的package包/类
private boolean isHardwareLevelSupported(
CameraCharacteristics characteristics, int requiredLevel) {
int deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
if (deviceLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
return requiredLevel == deviceLevel;
}
// deviceLevel is not LEGACY, can use numerical sort
return requiredLevel <= deviceLevel;
}
示例7: chooseCamera
import android.hardware.camera2.CameraCharacteristics; //导入方法依赖的package包/类
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;
}
示例8: getCameraId
import android.hardware.camera2.CameraCharacteristics; //导入方法依赖的package包/类
private String getCameraId() throws CameraAccessException {
String[] ids = mCameraManager.getCameraIdList();
for (String id : ids) {
CameraCharacteristics c = mCameraManager.getCameraCharacteristics(id);
Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING);
if (flashAvailable != null && flashAvailable
&& lensFacing != null && lensFacing == CameraCharacteristics.LENS_FACING_BACK) {
return id;
}
}
return null;
}
示例9: cropRegionForZoom
import android.hardware.camera2.CameraCharacteristics; //导入方法依赖的package包/类
/**
* Calculates sensor crop region for a zoom level (zoom >= 1.0).
*
* @return Crop region.
*/
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);
}
示例10: isFrontFacing
import android.hardware.camera2.CameraCharacteristics; //导入方法依赖的package包/类
@Override
public boolean isFrontFacing(String deviceName) {
CameraCharacteristics characteristics = getCameraCharacteristics(deviceName);
return characteristics != null
&& characteristics.get(CameraCharacteristics.LENS_FACING)
== CameraMetadata.LENS_FACING_FRONT;
}
示例11: getCameraId
import android.hardware.camera2.CameraCharacteristics; //导入方法依赖的package包/类
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;
}
示例12: getCameraResolutionsFront
import android.hardware.camera2.CameraCharacteristics; //导入方法依赖的package包/类
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];
}
}
示例13: startCamera
import android.hardware.camera2.CameraCharacteristics; //导入方法依赖的package包/类
@Override
public void startCamera() {
try {
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraID);
StreamConfigurationMap configMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
int width = textureView.getWidth();
int height = textureView.getHeight();
//设置一个合适的预览尺寸,防止图像拉伸
// previewSize = getPreferredPreviewSize(configMap.getOutputSizes(SurfaceTexture.class), width, height);
previewSize = Util.getPreferredPreviewSize(configMap.getOutputSizes(ImageFormat.JPEG), width, height);
surfaceTexture.setDefaultBufferSize(previewSize.getWidth(),previewSize.getHeight());
Log.i(TAG, "previewSize info:" + previewSize.getWidth() + "x" + previewSize.getHeight());
surface = new Surface(surfaceTexture);
builder =cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
if (surface.isValid()) {
builder.addTarget(surface);
}
Log.i(TAG, "mTextureView info:" + textureView.getWidth() + "x" + textureView.getHeight());
cameraDevice.createCaptureSession(Arrays.asList(surface),sessionStateCallback,null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例14: getJPEGOrientation
import android.hardware.camera2.CameraCharacteristics; //导入方法依赖的package包/类
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;
}
示例15: getAvailableModeList
import android.hardware.camera2.CameraCharacteristics; //导入方法依赖的package包/类
@Override
public int[] getAvailableModeList(CameraCharacteristics characteristics) {
return characteristics.get(TONEMAP_AVAILABLE_TONE_MAP_MODES);
}