Skip to content Skip to sidebar Skip to footer

Camerax Previewview Screenshot

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 scree

Solution 1:

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

Solution 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

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

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

    returnnull
}

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

Cheers.

Post a Comment for "Camerax Previewview Screenshot"