imageCapture.takePicture(cameraExecutor, new ImageCapture.OnImageCapturedCallback() { @Override public void onCaptureSuccess(@NonNull ImageProxy image) { // 在这里处理图像数据 }
@Override public void onError(@NonNull ImageCaptureException exception) { // 图像捕获出现错误 } });
val photoFile = File( outputDirectory, SimpleDateFormat(FILENAME_FORMAT, Locale.US) .format(System.currentTimeMillis()) + ".jpg")
val outputOptions = ImageCapture.OutputFileOptions.Builder(photoFile).build()
imageCapture.takePicture( outputOptions, ContextCompat.getMainExecutor(this), object : ImageCapture.OnImageSavedCallback { override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) { // 在这里处理保存后的图像数据 }
override fun onError(exception: ImageCaptureException) {
// 图像保存过程中出现错误
}
})
注意:在重新设置图像保存位置时,需要确保所在文件夹已经存在或者可以创建;同时,需要确保重新设置的保存位置具有正确的文件扩展名。