简体   繁体   English

你如何使用 Textureview 作为 cameraX 的预览 [Java]

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

I followed the guides on cameraX which all use PreviewView for displaying the camera output using preview.setSurfaceProvider(PreviewView.createSurfaceProvider());我遵循了 cameraX 上的指南,这些指南都使用 PreviewView 来显示相机 output 使用preview.setSurfaceProvider(PreviewView.createSurfaceProvider());

How do I set the preview to use a textureview instead of a PreviewView如何设置预览以使用 textureview 而不是 PreviewView

You can specify which view to use in PreviewView between SurfaceView and TextureView.您可以在 SurfaceView 和 TextureView 之间指定在 PreviewView 中使用哪个视图。 Before setting surfaceProvider, set the implementation mode设置surfaceProvider前,设置实现方式

previewView.implementationMode = PreviewView.ImplementationMode.COMPATIBLE

Here previewView is the XML id of PreviewView.这里的 previewView 是 PreviewView 的 XML id。 PreviewView.ImplementationMode.COMPATIBLE is for TextureView. PreviewView.ImplementationMode.COMPATIBLE用于 TextureView。 After setting this, the PreviewView will use TextureView to show Camera.设置后,PreviewView 将使用 TextureView 显示 Camera。

The implementation mode for SurfaceView is PreviewView.ImplementationMode.COMPATIBLE SurfaceView 的实现方式为PreviewView.ImplementationMode.COMPATIBLE

This is compatible with这是兼容的

androidx.camera:camera-view:1.0.0-alpha22

For this version, you need to change对于这个版本,您需要更改

preview.setSurfaceProvider(PreviewView.createSurfaceProvider()); preview.setSurfaceProvider(PreviewView.createSurfaceProvider());

to preview.setSurfaceProvider(previewView.getSurfaceProvider)到 preview.setSurfaceProvider(previewView.getSurfaceProvider)

my device previewView.setImplementationMode not show, what reason i can't understand.我的设备 previewView.setImplementationMode 不显示,我不明白是什么原因。 implementation 'androidx.camera:camera-view:1.1.0-alpha22' also using but why not work?实现 'androidx.camera:camera-view:1.1.0-alpha22' 也在使用,但为什么不起作用?

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

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