When using the Camera preview on android, there is a setPreviewCallback method to get the preview frames. (The API doc says it will do that.)
However, I never saw the callback is being called.
try { callbackBuffer = new byte[mCamera.getParameters().getPreviewSize().width * mCamera.getParameters().getPreviewSize().height * (ImageFormat.getBitsPerPixel(mCamera.getParameters().getPreviewFormat()) / 8)]; mCamera.addCallbackBuffer(callbackBuffer); mCamera.setPreviewCallbackWithBuffer(this); mCamera.setPreviewDisplay(holder); mCamera.startPreview(); } catch (IOException e) { Log.d(TAG, "Error setting camera preview: " + e.getMessage()); } |
Not works.
try { mCamera.setPreview(@Override public void onPreviewFrame(byte[] data, Camera camera) { Log.i(TAG, "preview"); } }); mCamera.setPreviewDisplay(holder); mCamera.startPreview(); } catch (IOException e) { Log.d(TAG, "Error setting camera preview: " + e.getMessage()); } |
Nope.
I could find a bug report about it.
onPreviewFrame never called when using setPreviewCallback
It seems like a bug on Android ICS, but it’s not clear which version is fixed. My device is 4.1.2 and just not working, and there will be so many people with ICS, because the Android device manufacturers doesn’t provide the OS update for the customers.
And android OS developers are not providing any explanation or the workaround to avoid it.
Developing on Android is just a mess..