gpt4 book ai didi

SurfaceView 上的 Android 中心 CameraPreview

转载 作者:行者123 更新时间:2023-11-29 00:25:41 28 4
gpt4 key购买 nike

我正在开发适用于 Android 的人脸检测应用程序(我的设备是装有 Android 4.1.2 的 Nexus S)。我的 SurfaceView 大小自动设置为 800x480,但我的最大相机分辨率为 720x480。我试图在其有效的 onLayout() 方法中更改 SurfaceView 的大小,但后来我在预览中丢失了 80px。是否可以拉伸(stretch)或至少居中 CameraPreview?

谢谢

最佳答案

可以使用 Camera.Parameters 更改 CameraPreview 大小。但我建议将 surfaceview 放在屏幕中央。这是代码。我没有执行代码,但它可能有效。

// Center the child SurfaceView within the parent.
final int width = r - l;
final int height = b - t;
if (width * previewHeight > height * previewWidth) {
final int surfaceViewWidth = previewWidth * height / previewHeight;
surfaceView.layout((int)((width - surfaceViewWidth)*0.5), 0, (int)((width + surfaceViewWidth)*0.5), height);
} else {
final int surfaceViewHeight = previewHeight * width / previewWidth;
surfaceView.layout(0, (int)((height - surfaceViewHeight)*0.5), width, (int)((height + surfaceViewHeight)*0.5));
}

关于SurfaceView 上的 Android 中心 CameraPreview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19735777/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com