简体   繁体   English

Android CameraX 裁剪 media.Image?

[英]Android CameraX cropping media.Image?

I am using CameraX for capturing images then feeding into mlkit scanner to scan barcodes, I have created a crop rect and applied to the media.image but it doesn't seem cropping the frame...我正在使用 CameraX 捕获图像,然后输入 mlkit 扫描仪以扫描条形码,我创建了一个裁剪矩形并应用于 media.image 但它似乎没有裁剪框架...

@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)
    }
}

I tried saving the media.Image fed to scanner to a bitmap and that is not cropped too.. Let me know what I am doing wrong.我尝试将送入扫描仪的媒体图像保存为位图,但也没有裁剪。让我知道我做错了什么。

I checked this answer but it is explaining with bitmaps and I am working with media.Image我检查了这个答案,但它是用位图解释的,我正在使用 media.Image

Android: How to crop images using CameraX? Android:如何使用 CameraX 裁剪图像?

ImageProxy.setCropRect()is just metadata that is passed along with the Image, and it is up to the consumer of the Image to apply the crop rect while accessing the pixels. ImageProxy.setCropRect() 只是与图像一起传递的元数据,由图像的使用者在访问像素时应用裁剪矩形。 ImageProxy.setCropRect() does not affect the crop rect of the underlying android.media.Image, it only changes the crop rect metadata for the ImageProxy instance. ImageProxy.setCropRect() 不影响底层android.media.Image 的crop rect,它只改变ImageProxy 实例的crop rect 元数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM