更新时间:2022-01-11 21:19:10
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)
和Camera.Parameters.setPictureFormat(int format)
之类的API来做到这一点.Camera.PictureCallback
来实现.Camera.startPreview()
.如果您未在拍照前调用此功能,则会出现异常. (注意:您无需先执行Camera.setPreviewdisplay(SurfaceHolder display)
.)camera.takePicture()
.然后,您可以将捕获的图像存储在指定的文件中.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.
这是我在Github上的示例代码,在评论中也有提及.
Here is my sample code on Github, it is also mentioned in the comment.