小编Kun*_*nBa的帖子

Android:如何使用 CameraX 裁剪图像?

我想拍摄一张照片并使用 CameraX 从中心裁剪出一个 25x25 dp 的正方形。我读过使用 ImageCapture 可以进行裁剪,但不幸的是到目前为止几乎没有类似的例子。

val imageCaptureConfig = ImageCaptureConfig.Builder().apply {
    setTargetAspectRatio(Rational(1, 1))
    setCaptureMode(ImageCapture.CaptureMode.MIN_LATENCY)
}.build()

val imageCapture = ImageCapture(imageCaptureConfig)
btn_take_photo.setOnClickListener {
    imageCapture.takePicture(
        object : ImageCapture.OnImageCapturedListener() {
            override fun onCaptureSuccess(image: ImageProxy?, rotationDegrees: Int) {
                super.onCaptureSuccess(image, rotationDegrees)

                // image manipulation here?
            }
        }
    )
}
Run Code Online (Sandbox Code Playgroud)

android android-camerax

7
推荐指数
3
解决办法
8800
查看次数

标签 统计

android ×1

android-camerax ×1