为了预览相机,我在下面编写了代码段。我无法获得任何预览。你能帮我解决问题吗?
我已经为我的应用程序配置了权限;
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
我已经创建了表面位置
<SurfaceView
android:id="@+id/cameraView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
我在下面编写了代码段来预览相机;
public class MainActivity extends Activity {
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.cameraView);
surfaceHolder = surfaceView.getHolder();
}
private void preview ( ) {
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
} catch ( IOException void_) {
;
}
}