use of androidx.camera.core.ImageProxy in project Signal-Android by signalapp.
the class CameraXFragment method onCaptureClicked.
private void onCaptureClicked() {
Stopwatch stopwatch = new Stopwatch("Capture");
CameraXSelfieFlashHelper flashHelper = new CameraXSelfieFlashHelper(requireActivity().getWindow(), camera, selfieFlash);
camera.takePicture(Executors.mainThreadExecutor(), new ImageCapture.OnImageCapturedCallback() {
@Override
public void onCaptureSuccess(@NonNull ImageProxy image) {
flashHelper.endFlash();
SimpleTask.run(CameraXFragment.this.getViewLifecycleOwner().getLifecycle(), () -> {
stopwatch.split("captured");
try {
return CameraXUtil.toJpeg(image, camera.getCameraLensFacing() == CameraSelector.LENS_FACING_FRONT);
} catch (IOException e) {
Log.w(TAG, "Failed to encode captured image.", e);
return null;
} finally {
image.close();
}
}, result -> {
stopwatch.split("transformed");
stopwatch.stop(TAG);
if (result != null) {
controller.onImageCaptured(result.getData(), result.getWidth(), result.getHeight());
} else {
controller.onCameraError();
}
});
}
@Override
public void onError(ImageCaptureException exception) {
Log.w(TAG, "Failed to capture image", exception);
flashHelper.endFlash();
controller.onCameraError();
}
});
flashHelper.startFlash();
}
use of androidx.camera.core.ImageProxy in project Signal-Android by WhisperSystems.
the class CameraXFragment method onCaptureClicked.
private void onCaptureClicked() {
Stopwatch stopwatch = new Stopwatch("Capture");
CameraXSelfieFlashHelper flashHelper = new CameraXSelfieFlashHelper(requireActivity().getWindow(), camera, selfieFlash);
camera.takePicture(Executors.mainThreadExecutor(), new ImageCapture.OnImageCapturedCallback() {
@Override
public void onCaptureSuccess(@NonNull ImageProxy image) {
flashHelper.endFlash();
SimpleTask.run(CameraXFragment.this.getViewLifecycleOwner().getLifecycle(), () -> {
stopwatch.split("captured");
try {
return CameraXUtil.toJpeg(image, camera.getCameraLensFacing() == CameraSelector.LENS_FACING_FRONT);
} catch (IOException e) {
Log.w(TAG, "Failed to encode captured image.", e);
return null;
} finally {
image.close();
}
}, result -> {
stopwatch.split("transformed");
stopwatch.stop(TAG);
if (result != null) {
controller.onImageCaptured(result.getData(), result.getWidth(), result.getHeight());
} else {
controller.onCameraError();
}
});
}
@Override
public void onError(ImageCaptureException exception) {
Log.w(TAG, "Failed to capture image", exception);
flashHelper.endFlash();
controller.onCameraError();
}
});
flashHelper.startFlash();
}
Aggregations