本文整理汇总了Java中android.hardware.camera2.CameraAccessException类的典型用法代码示例。如果您正苦于以下问题:Java CameraAccessException类的具体用法?Java CameraAccessException怎么用?Java CameraAccessException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CameraAccessException类属于android.hardware.camera2包,在下文中一共展示了CameraAccessException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setManualFocusAt
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
void setManualFocusAt(int x, int y) {
int mDisplayOrientation = getActivity().getWindowManager().getDefaultDisplay().getRotation();
float points[] = new float[2];
points[0] = (float) x / mTextureView.getWidth();
points[1] = (float) y / mTextureView.getHeight();
Matrix rotationMatrix = new Matrix();
rotationMatrix.setRotate(mDisplayOrientation, 0.5f, 0.5f);
rotationMatrix.mapPoints(points);
if (mPreviewRequestBuilder != null) {
mIsManualFocusing = true;
updateManualFocus(points[0], points[1]);
if (mPreviewSession != null) {
try {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_START);
mPreviewSession.capture(mPreviewRequestBuilder.build(), null, mBackgroundHandler);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
mPreviewSession.setRepeatingRequest(mPreviewRequestBuilder.build(),
null, mBackgroundHandler);
} catch (CameraAccessException | IllegalStateException e) {
Log.e(TAG, "Failed to set manual focus.", e);
}
}
resumeAutoFocusAfterManualFocus();
}
}
示例2: setFlash
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
@Override
void setFlash(int flash) {
if (mFlash == flash) {
return;
}
int saved = mFlash;
mFlash = flash;
if (mPreviewRequestBuilder != null) {
updateFlash();
if (mCaptureSession != null) {
try {
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(),
mCaptureCallback, null);
} catch (CameraAccessException e) {
mFlash = saved; // Revert
}
}
}
}
示例3: unlockFocus
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
* Unlock the focus. This method should be called when still image capture sequence is
* finished.
*/
private void unlockFocus() {
try {
// Reset the auto-focus trigger
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
setAutoFlash(mPreviewRequestBuilder);
mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
mBackgroundHandler);
// After this, the camera will go back to the normal state of preview.
mState = STATE_PREVIEW;
mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例4: onOpened
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
@Override
public void onOpened(CameraDevice camera) {
checkIsOnCameraThread();
Logging.d(TAG, "Camera opened.");
cameraDevice = camera;
final SurfaceTexture surfaceTexture = surfaceTextureHelper.getSurfaceTexture();
surfaceTexture.setDefaultBufferSize(captureFormat.width, captureFormat.height);
surface = new Surface(surfaceTexture);
List<Surface> surfaces = new ArrayList<Surface>();
surfaces.add(surface);
if (mediaRecorderSurface != null) {
Logging.d(TAG, "Add MediaRecorder surface to capture session.");
surfaces.add(mediaRecorderSurface);
}
try {
camera.createCaptureSession(surfaces, new CaptureSessionCallback(), cameraThreadHandler);
} catch (CameraAccessException e) {
reportError("Failed to create capture session. " + e);
return;
}
}
示例5: unlockFocus
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
* Unlock the focus. This method should be called when still image capture sequence is
* finished.
*/
private void unlockFocus() {
try {
// Reset the auto-focus trigger
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
mPreviewSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
mBackgroundHandler);
updateAutoFocus();
updateFlash(mPreviewRequestBuilder);
// After this, the camera will go back to the normal state of preview.
mState = STATE_PREVIEW;
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
mPreviewSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例6: setupCameraIfNeeded
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
private boolean setupCameraIfNeeded() {
if (cameraId != null) {
return true;
}
try {
cameraId = cameraManager.getCameraIdList()[0]; // Usually back camera is at 0 position
} catch (CameraAccessException e) {
Log.v(TAG, "failed to set up camera");
return false;
}
torchEnabled = false;
Handler handler = new Handler();
torchCallback = new CameraManager.TorchCallback() {
@Override
public void onTorchModeChanged(@NonNull String cameraId, boolean enabled) {
super.onTorchModeChanged(cameraId, enabled);
torchEnabled = enabled;
}
};
cameraManager.registerTorchCallback(torchCallback, handler);
Log.v(TAG, "registered torch callback");
return true;
}
示例7: setAutoFocus
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
@Override
void setAutoFocus(boolean autoFocus) {
if (mAutoFocus == autoFocus) {
return;
}
mAutoFocus = autoFocus;
if (mPreviewRequestBuilder != null) {
updateAutoFocus();
if (mCaptureSession != null) {
try {
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(),
mCaptureCallback, null);
} catch (CameraAccessException e) {
mAutoFocus = !mAutoFocus; // Revert
}
}
}
}
示例8: startCaptureSession
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
* <p>Starts a capture session for camera preview.</p>
* <p>This rewrites {@link #mPreviewRequestBuilder}.</p>
* <p>The result will be continuously processed in {@link #mSessionCallback}.</p>
*/
void startCaptureSession() {
if (!isCameraOpened() || !mPreview.isReady() || mImageReader == null) {
return;
}
Size previewSize = chooseOptimalSize();
mPreview.setBufferSize(previewSize.getWidth(), previewSize.getHeight());
Surface surface = mPreview.getSurface();
try {
mPreviewRequestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mPreviewRequestBuilder.addTarget(surface);
mCamera.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
mSessionCallback, null);
} catch (CameraAccessException e) {
throw new RuntimeException("Failed to start camera session");
}
}
示例9: openCamera
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
* 相机开启
* @param width TextureView的宽度
* @param height TextureView的高度
*/
private void openCamera(int width, int height) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
// requestCameraPermission();
return;
}
setUpCameraOutputs(width, height);
configureTransform(width, height);
try {
cameraManager.openCamera(cameraID, deviceStateCallback, mainHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例10: unlockFocus
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
* Unlocks the auto-focus and restart camera preview. This is supposed to be called after
* capturing a still picture.
*/
void unlockFocus() {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_CANCEL);
try {
mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, null);
updateAutoFocus();
updateFlash();
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback,
null);
mCaptureCallback.setState(PictureCaptureCallback.STATE_PREVIEW);
} catch (CameraAccessException e) {
Log.e(TAG, "Failed to restart camera preview.", e);
}
}
示例11: openCamera
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
private void openCamera(String cameraId) {
try {
// CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(cameraId);
// characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
if (ActivityCompat.checkSelfPermission(getContext(), permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
setUpCameraOutputs(cameraId, ttv_camera.getWidth(), ttv_camera.getHeight());
configureTransform(ttv_camera.getWidth(), ttv_camera.getHeight());
mCameraManager.openCamera(cameraId, mCameraDeviceStateCallback, mHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例12: setRepeatingBurst
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
* Set a repeating burst request.
*/
public void setRepeatingBurst(final List<CaptureRequest> requests,
final CameraCaptureSession.CaptureCallback listener, final Handler handler) {
mCameraHandler.post(() -> {
try {
mCameraSession.setRepeatingBurst(requests, listener, handler);
} catch (CameraAccessException e) {
String errorMessage = mErrorDisplayer.getErrorString(e);
mErrorDisplayer.showErrorDialog(errorMessage);
}
});
}
示例13: start
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
private void start() {
checkIsOnCameraThread();
Logging.d(TAG, "start");
try {
cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
} catch (final CameraAccessException e) {
reportError("getCameraCharacteristics(): " + e.getMessage());
return;
}
cameraOrientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
isCameraFrontFacing = cameraCharacteristics.get(CameraCharacteristics.LENS_FACING)
== CameraMetadata.LENS_FACING_FRONT;
findCaptureFormat();
openCamera();
}
示例14: takePicture
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
/**
* Begin a still image capture
*/
public void takePicture() {
if (mCameraDevice == null) {
Log.w(TAG, "Cannot capture image. Camera not initialized.");
return;
}
// Here, we create a CameraCaptureSession for capturing still images.
try {
mCameraDevice.createCaptureSession(
Collections.singletonList(mImageReader.getSurface()),
mSessionCallback,
null);
} catch (CameraAccessException cae) {
Log.d(TAG, "access exception while preparing pic", cae);
}
}
示例15: setFlashlight
import android.hardware.camera2.CameraAccessException; //导入依赖的package包/类
public void setFlashlight(boolean enabled) {
boolean pendingError = false;
synchronized (this) {
if (mFlashlightEnabled != enabled) {
mFlashlightEnabled = enabled;
try {
mCameraManager.setTorchMode(mCameraId, enabled);
} catch (CameraAccessException e) {
Log.e(TAG, "Couldn't set torch mode", e);
mFlashlightEnabled = false;
pendingError = true;
}
}
}
dispatchModeChanged(mFlashlightEnabled);
if (pendingError) {
dispatchError();
}
}