Android camerax 拍照到变量
Android camerax take picture into variable
我需要将在android中拍摄的照片保存到一个变量(字符串)中
这是我的代码:
var imageCapture = ImageCapture.Builder().build()
val captureMode = ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY
val flashMode = ImageCapture.FLASH_MODE_AUTO
val aspectRatio = AspectRatio.RATIO_16_9
val metrics = DisplayMetrics().also { previewView.display.getRealMetrics(it) }
val screenSize = Size(metrics.widthPixels, metrics.heightPixels)
imageCapture = ImageCapture.Builder()
.setCaptureMode(captureMode)
.setTargetAspectRatio(aspectRatio)
.setFlashMode(flashMode)
.setTargetResolution(screenSize)
.setTargetName("CameraConference")
.build()
imageCapture 有一个名为 takePicture 的方法
我不明白如何使用 imageCapture.takePicture 所以它的输出将是一个变量 (string)
谢谢
您可以使用 ImageCapture#takePicture(Executor executor, ImageCapture.OnImageCapturedCallback callback) API to return an in-memory picture. The returned object is an ImageProxy, which include the actual bytes as well as how the bytes should be transformed to present to end users. ImageProxy#getPlanes() 包含缓冲区字节。
要将 ImageProxy 字节转换为位图,请参阅代码示例 here。
我需要将在android中拍摄的照片保存到一个变量(字符串)中 这是我的代码:
var imageCapture = ImageCapture.Builder().build()
val captureMode = ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY
val flashMode = ImageCapture.FLASH_MODE_AUTO
val aspectRatio = AspectRatio.RATIO_16_9
val metrics = DisplayMetrics().also { previewView.display.getRealMetrics(it) }
val screenSize = Size(metrics.widthPixels, metrics.heightPixels)
imageCapture = ImageCapture.Builder()
.setCaptureMode(captureMode)
.setTargetAspectRatio(aspectRatio)
.setFlashMode(flashMode)
.setTargetResolution(screenSize)
.setTargetName("CameraConference")
.build()
imageCapture 有一个名为 takePicture 的方法 我不明白如何使用 imageCapture.takePicture 所以它的输出将是一个变量 (string)
谢谢
您可以使用 ImageCapture#takePicture(Executor executor, ImageCapture.OnImageCapturedCallback callback) API to return an in-memory picture. The returned object is an ImageProxy, which include the actual bytes as well as how the bytes should be transformed to present to end users. ImageProxy#getPlanes() 包含缓冲区字节。
要将 ImageProxy 字节转换为位图,请参阅代码示例 here。