Android CameraX裁剪媒体.图像



我使用CameraX拍摄图像,然后输入mlkit扫描仪扫描条形码,我创建了一个裁剪矩形并应用于媒体。图像,但似乎没有裁剪框架。。。

@androidx.camera.core.ExperimentalGetImage
override fun analyze(imageProxy: ImageProxy) {
imageProxy.image ?. let {
val rotationDegrees = imageProxy.imageInfo.rotationDegrees
val imageHeight = it.height
val imageWidth = it.width
val cropRect = Rect(0, 0, imageWidth, imageHeight)
cropRect.inset(
(imageWidth/ 2),
(imageHeight/ 2)
)
it.cropRect = cropRect
val image = InputImage.fromMediaImage(it, imageProxy.imageInfo.rotationDegrees)
}
}

我试着保存媒体。将图像馈送到扫描仪的位图中,并且该位图也不会被裁剪。。让我知道我做错了什么。

我检查了这个答案,但它是用位图解释的,我正在处理媒体。图像

安卓:如何使用CameraX裁剪图像?

ImageProxy.setCropRect((只是与图像一起传递的元数据,由图像的使用者在访问像素时应用裁剪矩形。ImageProxy.setCropRect((不影响底层android.media.Image的裁剪矩形,它只更改ImageProxy实例的裁剪矩形元数据。

最新更新