I have create a application in Android that using a camera I can measure out the distance between user\'s face to the phone screen.
Problem description:
You can refer this Question, which discuss how to do video record in the service. The steps to capture image is same as it.
To achieve your requirement, you may need:
Camera.getParameters()
, Camera.setParameters()
, Camera.Parameters.setPictureSize(int with, int height)
and Camera.Parameters.setPictureFormat(int format)
to do so.Camera.PictureCallback
to do so.Camera.startPreview()
before you takeing picutre. If you don't call this function before taking picture, you will get exception. (Note: You don't need to do Camera.setPreviewdisplay(SurfaceHolder display)
first.)camera.takePicture()
in your service. Then you can get the captured image stored on the file you specified.After it work, don forget to maintain the resource durning lifecycle to acquire/release camera correctly.
Here is my sample code on Github, it is also mentioned in the comment.