Taking picture without SurfaceView or without Phot

2019-07-19 02:53发布

问题:

I need to take a photo from phone camera to analyze it, but I do not need to show the content (image of camera) on SurfaceView. Can I use Camera class without SurfaceView holder? One way is to simply hide SurfaceView but Is there a way to not using it at all?

I tried like this but it throws an error: takePicture failed

onCreate:

mCamera = getCameraInstance();   //private Camera mCamera;  
mCamera.startPreview();

button.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {

      mCamera.takePicture(null, null, mPicture);

   }
});

Camera:

public static Camera getCameraInstance() {
            Camera c = null;
            try {
                c = Camera.open(); // attempt to get a Camera instance
            } catch (Exception e) {
                e.printStackTrace();
            }
            return c; // returns null if camera is unavailable
        }

    private Camera.PictureCallback mPicture = new Camera.PictureCallback() {

        @Override
        public void onPictureTaken(byte[] data, Camera camera) {

            System.out.println("CLICK");
        }
    };

回答1:

I solve my problem by puting new view over the SurficeView so surficeView was not seen. I spend quite a time by searching for other solution but without success.