简体   繁体   English

是否可以在显示之前处理camerax预览的数据?

[英]Is it possible to process data of camerax preview before displaying it?

I would like to process the image that is displayed in preview and display display the processed version.我想处理预览中显示的图像并显示处理后的版本。

I've tried modifying it using the imageProxy in analyzer, but that does not seem to be doing anything.我试过在分析器中使用 imageProxy 修改它,但这似乎没有做任何事情。

I know that older camera apis are able to do it, but CameraX does not seem to have the apis.我知道较旧的相机 api 能够做到这一点,但 CameraX 似乎没有这些 api。

No, this flow is not supported by cameraX.不,cameraX 不支持此流程。 Actually, this use case has never been supported by any Android camera API.实际上,此用例从未得到任何 Android 相机 API 的支持。 What you have to do, is create your own renderer (preferably, OpenGL), hide the native preview surface, and send the modified frames to your renderer.您需要做的是创建您自己的渲染器(最好是 OpenGL),隐藏本机预览表面,并将修改后的帧发送到您的渲染器。

Hope this will help:希望这会有所帮助:


        val mediaImage = imageProxy.image ?: return
        var bitmap = ImageUtils.convertYuv420888ImageToBitmap(mediaImage)

        val rotationDegrees = imageProxy.imageInfo.rotationDegrees

        val matrix = Matrix()
        matrix.postRotate(rotationDegrees.toFloat())

        bitmap =
            Bitmap.createBitmap(bitmap, 0, 0, mediaImage.width, mediaImage.height, matrix, true)
        val cropHeight = if (bitmap.width < previewView.width) {
            // if preview area larger than analysing image
            val koeff = bitmap.width.toFloat() / previewView.width.toFloat()
            previewView.height.toFloat() * koeff
        } else {
            // if preview area smaller than analysing image
            val prc = 100 - (previewView.width.toFloat() / (bitmap.width.toFloat() / 100f))
            previewView.height + ((previewView.height.toFloat() / 100f) * prc)
        }

        val cropTop = (bitmap.height / 2) - ((cropHeight) / 2)

        if (cropTop > 0) {
            Bitmap.createBitmap(bitmap, 0, cropTop.toInt(), bitmap.width, cropHeight.toInt())
                .also { process(it, imageProxy) }
        } else {
            imageProxy.image?.let { process(it, imageProxy) }
        }

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

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