private SurfaceHolder mHolder;
private SurfaceView mSurfaceView; private Camera mCamera;mSurfaceView = (SurfaceView) this.findViewById(R.id.camsurfaceView1);
mHolder = mSurfaceView.getHolder(); mHolder.addCallback(this); mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mCamera = Camera.open();
Parameters p = mCamera.getParameters(); p.setFlashMode(Parameters.FLASH_MODE_TORCH); p.setPictureSize(320, 240); mCamera.setParameters(p); try { mCamera.setPreviewDisplay(mHolder); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } mCamera.startPreview();// 开启预览