CameraX PreviewView Screenshot

强颜欢笑 提交于 2020-07-23 07:07:45

问题


I want to convert CameraX preview to bitmap from previewView. Something similar to textureView.bitmap

I have tried it with a textureview and it works perferctly, i can take a screenshot of the cameraview but the camera is stretched.


回答1:


PreviewView now supports screenshot by calling PreviewView.getBitmap(). See: https://developer.android.com/reference/androidx/camera/view/PreviewView#getBitmap()




回答2:


I finally found the answer in this link

First set preferred implementationmode to TextureView as below:

previewView.preferredImplementationMode = PreviewView.ImplementationMode.TEXTURE_VIEW

Then get the bitmap

fun getPreviewViewBitmap(width: Int, height: Int): Bitmap? {
    val previewChildView = previewView.getChildAt(0)

    if (previewChildView is TextureView)
        return previewChildView.getBitmap(width, height)

    return null
}

Note: I have only tested on a few devices and it works great.

Cheers.



来源:https://stackoverflow.com/questions/61719500/camerax-previewview-screenshot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!