在Android 3.0或更高版本上,您可以使用setPreviewTexture方法将预览数据导入OpenGL纹理,然后在GLSurfaceView或等效物中呈现到多个四边形中。
但我不知道如何在GLSurfaceView
中呈现多个四边形。我需要支持Android 4.0+。但我不想使用预览回调的预览帧。它会导致显着的延迟。任何帮助将不胜感激。谢谢!
这是我的单个预览代码
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="10" >
<TextureView
android:id="@+id/textureView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5" />
<TextureView
android:id="@+id/textureView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5" />
</LinearLayout>
</RelativeLayout>
MainActivity.java
public class MainActivity extends Activity implements SurfaceTextureListener{
private Camera mCamera;
private TextureView mTextureView1;
private TextureView mTextureView2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextureView1 = (TextureView) findViewById(R.id.textureView1);
mTextureView2 = (TextureView) findViewById(R.id.textureView2);
mTextureView1.setSurfaceTextureListener(this);
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width,
int height) {
try {
mCamera = Camera.open(getCameraId());
mCamera.setPreviewTexture(surface);
CameraInfo cameraInfo = new CameraInfo();
Camera.getCameraInfo(getCameraId(), cameraInfo);
setCameraDisplayOrientation(this, getCameraId(), mCamera);
mCamera.startPreview();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
try {
mCamera.stopPreview();
mCamera.release();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width,
int height) {
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
}
输出:
![在此输入图片描述](https://istack.dev59.com/zD0uY.webp)
onPreviewFrame
来获取单个帧,因为它会引入一些延迟。 - Abhishek V