我正在尝试相机预览
这是我的代码,它不会抛出任何错误,但屏幕仍然是黑色的。有任何想法吗?
this.setContentView(R.layout.camerapreview);
SurfaceView cameraSurface = (SurfaceView)findViewById(R.id.cpPreview);
SurfaceHolder holder = cameraSurface.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
this.camera = Camera.open();
this.camera.setPreviewDisplay(holder);
this.camera.startPreview();
相机预览.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<SurfaceView
android:id="@+id/cpPreview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
</SurfaceView>
</LinearLayout>