я пробую предварительный просмотр камеры
Это - мой код, и он не бросает ошибки, но экран является все еще черным. Какие-либо идеи?
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();
camerapreview.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>
Вы слишком рано вызываете последние три линии. Вы должны дождаться подготовки поверхности перед вызовом setPreviewDisplay ()
, и вы должны дождаться, пока поверхность будет изменена ( surfaceChanged ()
) перед вызовом startPreview ( )
. В этом проекте есть все, что вам нужно.