带有SurfaceView的Camera2

slo*_*ott 10 android surfaceview android-camera textureview

我正在尝试使用简单的SurfaceView使新的Camera2工作,我在实时预览中遇到了一些问题.在某些设备上,图像会按比例拉伸,而在其他设备上看起来很好.

我已经设置了一个SurfaceView,我以编程方式调整以适应预览流大小的大小.

在Nexus 5上,这看起来不错,但一台三星设备就此消失了.此外,三星设备在预览的右侧部分有黑色边框.

是否真的无法使用SurfaceView,或者是时候切换到TextureView了?

Bud*_*ius -1

我从未使用过 Camera2(但对新技术非常感兴趣),我所能建议您的就是遵循示例。如果您仔细检查,示例使用 Custom TextureView,您应该尝试将其复制到您的项目中:

http://developer.android.com/samples/Camera2Basic/src/com.example.android.camera2basic/AutoFitTextureView.html

/**
 * A {@link TextureView} that can be adjusted to a specified aspect ratio.
 */
public class AutoFitTextureView extends TextureView {
Run Code Online (Sandbox Code Playgroud)

还考虑到SurfaceView和TextureView之间的区别(理论上)只是你可以在布局中用作普通视图,而另一个通过视图层次结构“打出一个整体”,并且Camera2仅在API21+中可用......应该有迁移到没有坏处TextureView