How do you use Textureview as a preview for cameraX [Java]

1.7k Views Asked by At

I followed the guides on cameraX which all use PreviewView for displaying the camera output using preview.setSurfaceProvider(PreviewView.createSurfaceProvider());

How do I set the preview to use a textureview instead of a PreviewView

1

There are 1 best solutions below

0
Ashiqur Rahman Tahmid On

You can specify which view to use in PreviewView between SurfaceView and TextureView. Before setting surfaceProvider, set the implementation mode

previewView.implementationMode = PreviewView.ImplementationMode.COMPATIBLE

Here previewView is the XML id of PreviewView. PreviewView.ImplementationMode.COMPATIBLE is for TextureView. After setting this, the PreviewView will use TextureView to show Camera.

The implementation mode for SurfaceView is PreviewView.ImplementationMode.PERFORMANCE

This is compatible with

androidx.camera:camera-view:1.0.0-alpha22