Camera frames in a service / background process

瘦欲@ 提交于 2019-11-27 04:08:16

问题


For scientific measurements, I would like to access the camera frames from a service. The idea is to analyze the images coming from the camera in real-time under some conditions. Since the phone might be restarted or simply locked, it should be possible to start the process from a service.

For now, I was satisfied by using a Camera.Callback and the onPreviewFrame callback, but it appears that it only works if my application is running in foreground. More precisely, the camera requires a valid SurfaceView in order to call the onPreviewFrame function. And a SurfaceView created in an Activity is destroyed when the activity is minimized / finished.

I just cannot find a way to get the frames from a background process. Actually, it works on a Galaxy Note 10.1, but the Galaxy S4 requires a valid SurfaceView.

Is there a way to achieve this?

There are many topics about this on StackOverflow, but none worked for me.


回答1:


You can send the preview to a SurfaceTexture instead (setPreviewTexture()). This won't disappear when the app is paused. Requires API 11+.

You can see various applications of this technique in Grafika, which is generally doing video or GLES manipulation rather than stills, but the idea is similar.



来源:https://stackoverflow.com/questions/24205661/camera-frames-in-a-service-background-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!