本文整理匯總了Java中android.hardware.camera2.CameraCharacteristics.LENS_FACING_BACK屬性的典型用法代碼示例。如果您正苦於以下問題:Java CameraCharacteristics.LENS_FACING_BACK屬性的具體用法?Java CameraCharacteristics.LENS_FACING_BACK怎麽用?Java CameraCharacteristics.LENS_FACING_BACK使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.hardware.camera2.CameraCharacteristics
的用法示例。
在下文中一共展示了CameraCharacteristics.LENS_FACING_BACK屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: open
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: getCameraInfo
@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();
}
示例3: FlashController
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));
}
}
示例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: getCameraId
private String getCameraId() {
if (mCameraId == null) {
try {
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) {
mCameraId = id;
}
}
if (DEBUG) Log.d(TAG, "getCameraId: " + mCameraId);
} catch (Exception e) {
e.printStackTrace();
mTorchStatus = TORCH_STATUS_ERROR;
broadcastStatus();
stopSelf();
}
}
return mCameraId;
}
示例6: 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;
}
示例7: getCameraResolutionsBack
public Size[] getCameraResolutionsBack() {
try {
CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics("0");
if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING)
!= CameraCharacteristics.LENS_FACING_BACK) {
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];
}
}
示例8: 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;
}
}
示例9: getCameraId
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;
}
示例10: initCamera
private void initCamera() {
cameraID = "" + CameraCharacteristics.LENS_FACING_BACK;
cameraManager = (CameraManager) getContext().getSystemService(CAMERA_SERVICE);
try {
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getContext(), "請授權使用照相機", Toast.LENGTH_SHORT).show();
return;
}
//$ process in background
cameraManager.openCamera(cameraID, cameraStateCallback, backGroundHandler1);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例11: initCamera
private void initCamera() {
cameraId = "" + CameraCharacteristics.LENS_FACING_BACK;
cameraManager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);
try {
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getContext(), "沒有相機權限", Toast.LENGTH_SHORT).show();
} else {
cameraManager.openCamera(cameraId, cameraCallback, backgroundHandler);
}
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例12: initCamera
private void initCamera() {
cameraID = "" + CameraCharacteristics.LENS_FACING_BACK;
cameraManager = (CameraManager) getContext().getSystemService(CAMERA_SERVICE);
try {
if (ActivityCompat.checkSelfPermission(getContext(),Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getContext(), "請授權使用照相機", Toast.LENGTH_SHORT).show();
return;
}
cameraManager.openCamera(cameraID, cameraStateCallback, null);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例13: findAndOpenCamera
private void findAndOpenCamera() {
boolean cameraPermissions = checkCameraPermissions();
if (cameraPermissions) {
String errorMessage = "Unknown error";
boolean foundCamera = false;
initializeCamera();
if (cameraPermissions && mCameraOps != null) {
try {
// Find first back-facing camera that has necessary capability.
String[] cameraIds = mCameraManager.getCameraIdList();
for (String id : cameraIds) {
CameraCharacteristics info = mCameraManager.getCameraCharacteristics(id);
int facing = info.get(CameraCharacteristics.LENS_FACING);
int level = info.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
boolean hasFullLevel =
(level == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL);
int[] capabilities =
info.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES);
int syncLatency = info.get(CameraCharacteristics.SYNC_MAX_LATENCY);
boolean hasManualControl =
hasCapability(capabilities, CameraCharacteristics
.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR);
boolean hasEnoughCapability = hasManualControl && syncLatency ==
CameraCharacteristics.SYNC_MAX_LATENCY_PER_FRAME_CONTROL;
// All these are guaranteed by
// CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL, but checking
// for only the things we care about expands range of devices we can run on.
// We want:
// - Back-facing camera
// - Manual sensor control
// - Per-frame synchronization (so that exposure can be changed every
// frame)
if (facing == CameraCharacteristics.LENS_FACING_BACK &&
(hasFullLevel || hasEnoughCapability)) {
// Found suitable camera - get info, open, and set up outputs
mCameraInfo = info;
mCameraOps.openCamera(id);
configureSurfaces();
foundCamera = true;
break;
}
}
if (!foundCamera) {
errorMessage = getString(R.string.camera_no_good);
}
} catch (CameraAccessException e) {
errorMessage = getErrorString(e);
}
if (!foundCamera) {
showErrorDialog(errorMessage);
}
}
}
}