void startPreview() {
   mDisplayRotation = CameraUtil.getDisplayRotation(RegistCameraActivity.this);
   mDisplayOrientation = CameraUtil.getDisplayOrientation(mDisplayRotation, CURRENT_CAMERA);
   mCamera.setDisplayOrientation(mDisplayOrientation);
   try {
     mCamera.setPreviewDisplay(mSurfaceHolder);
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   mCamera.setPreviewCallback(RegistCameraActivity.this);
   //		mCamera.autoFocus(autoFocusCallback);
   mCamera.startPreview();
 }
 void switchCamera() {
   releaseCamera();
   if (CURRENT_CAMERA == CameraInfo.CAMERA_FACING_FRONT) {
     CURRENT_CAMERA = CameraInfo.CAMERA_FACING_BACK;
   } else {
     CURRENT_CAMERA = CameraInfo.CAMERA_FACING_FRONT;
   }
   mCamera = CameraUtil.getCameraInstance(CURRENT_CAMERA);
   initCameraParameters();
   startPreview();
 }
 void initCameraParameters() {
   Camera.Parameters parameters = mCamera.getParameters();
   parameters.setPictureFormat(ImageFormat.JPEG);
   List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes();
   // for(Size s:previewSizes){
   // System.out.println("("+s.width+","+s.height+")");
   // }
   rate = CameraUtil.getScreenRate(RegistCameraActivity.this);
   Size previewSize = CameraUtil.getPropPreviewSize(previewSizes, rate, 800);
   parameters.setPreviewSize(previewSize.width, previewSize.height);
   List<Camera.Size> pictureSizes = parameters.getSupportedPictureSizes();
   Size pictureSize = CameraUtil.getPropPictureSize(pictureSizes, rate, 800);
   parameters.setPictureSize(pictureSize.width, pictureSize.height);
   if (CURRENT_CAMERA == CameraInfo.CAMERA_FACING_FRONT) {
     mCameraOrientation = 270;
   } else {
     mCameraOrientation = 90;
   }
   parameters.setRotation(mCameraOrientation);
   //		parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
   mCamera.setParameters(parameters);
 }
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   if (mCamera == null) {
     mCamera = CameraUtil.getCameraInstance(CURRENT_CAMERA);
     if (mCamera != null) {
       try {
         mCamera.setPreviewDisplay(holder);
         initCameraParameters();
       } catch (IOException e) {
         // TODO Auto-generated catch block
         //					e.printStackTrace();
         showMessage("设置预览失败");
       }
     }
   }
 }
 @Override
 protected void onResume() {
   // TODO Auto-generated method stub
   super.onResume();
   if (mCamera != null) {
     releaseCamera();
     initSurface();
   } else {
     initSurface();
     if (mCamera == null) {
       mCamera = CameraUtil.getCameraInstance(CURRENT_CAMERA);
       if (mCamera != null) {
         try {
           mCamera.setPreviewDisplay(mSurfaceHolder);
           initCameraParameters();
         } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         }
       }
     }
     startPreview();
   }
 }
  void doFacedetect(byte[] data, Camera camera) {
    long start = System.currentTimeMillis();
    Bitmap bmp = CameraUtil.yuvimage2Bitmap(data, camera);
    Matrix matrix = new Matrix();
    matrix.postRotate(270);
    matrix.postScale(-1, 1);
    Bitmap tmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
    bmp.recycle();
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int heightScreen = dm.heightPixels;
    int widthScreen = dm.widthPixels;
    Bitmap tmp1 = Bitmap.createScaledBitmap(tmp, widthScreen, heightScreen, true);
    tmp.recycle();
    RectF rect = mFaceView.getRect();
    Bitmap tmp2 =
        Bitmap.createBitmap(
            tmp1,
            (int) rect.left,
            (int) rect.top,
            (int) (rect.right - rect.left),
            (int) (rect.bottom - rect.top));
    tmp1.recycle();
    Bitmap picture = tmp2.copy(Bitmap.Config.RGB_565, true);
    tmp2.recycle();

    int N_MAX = 1;
    FaceDetector faceDetector = new FaceDetector(picture.getWidth(), picture.getHeight(), N_MAX);
    Face[] faces = new Face[N_MAX];
    faceDetector.findFaces(picture, faces);

    for (Face f : faces) {
      try {
        PointF midPoint = new PointF();
        f.getMidPoint(midPoint);
        if (f.confidence() < 0.4) return;
        findFaceCount++;
        mFaceView.setFaceParameters(midPoint, f.eyesDistance());
        if (findFaceCount == 3) {
          showCapture();
          findFaceCount = 0;
        }
        if (modeSwitch.isChecked()) {
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          picture.compress(CompressFormat.JPEG, 100, out);
          byte[] picBytes = out.toByteArray();
          Intent intent = new Intent(RegistCameraActivity.this, DisplayActivity_.class);
          intent.putExtra("picture", picBytes);
          intent.putExtra("isRegist", true);
          intent.putExtra("auto", true);
          intent.putExtra("currentCamera", CURRENT_CAMERA);
          startActivity(intent);
        }

        //				System.out.println("YOU:"+midPoint);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        //				e.printStackTrace();
        mFaceView.setFaceParameters(null, 0);
        mFaceView.invalidate();
        findFaceCount = 0;
      } finally {
        picture.recycle();
      }
    }

    long end = System.currentTimeMillis();
    System.out.println("耗时:" + (end - start) + " ms");

    Timer timer = new Timer();
    TimerTask task =
        new TimerTask() {

          @Override
          public void run() {
            clearEyeCircle();
          }
        };
    timer.schedule(task, 200);
  }