Android: Accessing hardware camera preview frame data without drawing them

醉酒当歌 提交于 2019-12-04 01:51:26

I completely forgot I had this question up. 2 years and a couple of Android SDK versions later, we have a working system.

We're using an extended SurfaceTexture, cameraSurface with a reference to the required camera. Using cameraSurface's SurfaceTexture, we call

mCamera.setPreviewTexture(mSurfaceTexture);
mCamera.startPreview();

Then override the current active camera's previewCallback from your activity or wherever you need it.

mCamera.setPreviewCallback(new PreviewCallback() {

     public void onPreviewFrame(final byte[] data, final Camera camera) {
         // Process the contents of byte for whatever you need
     }
});

This allows you to continuously process what the camera sees, rather than just having to go through stored images. Of course, this will be limited to your camera's preview resolution (which may be different from the still capture or video resolutions).

If I get the time, I'll try to throw up a barebones working demo.

Edit: The SDK I had linked to is no longer freely available. You can still request one via the BitGym contact page.

Justin Slade

There is no getting around having the SurfaceView for image preview. What you could do is delegate the responsibility of capturing the byte[] to the apps implementing your library which would allows them to use your library for not only images from the camera but allows images that have already been taken.

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