简体   繁体   中英

Android camera preview callback buffer not filled: is always full of zeros

While Camera.PreviewCallback#onPreviewFrame does get called, the passed byte[] buffer is not populated by the camera: it is always full of zeros.

The reason why I'm using the deprecated API is that I was getting a very low framerate using the newer one. Since my cameras are considered LEGACY , I was recommended to try the deprecated API.

My code, where the callback does get called, but the buffer is empty:

camera = Camera.open();
camera.setParameters(configurator.getParameters());
Size size = configurator.getOutputSize();
camera.addCallbackBuffer(new byte[size.getWidth() * size.getHeight() * ImageFormat.getBitsPerPixel(ImageFormat.YV12) / 8]);
camera.setPreviewCallbackWithBuffer(this);
camera.startPreview();

One weird thing I see in the log is the following: when I call camera.setPreviewCallbackWithBuffer(this); , this debug message appears: D/Camera-JNI: (tid:3466)[release camera] - X context=0x0 .
Also, all modifications to the buffer are cleared: the buffer is actually being filled with zeros before each call to the callback.

The issue was the lack of light compared to the exposure time: I have set my preview FPS range to the maximum one, but this caused the exposure time to be too low compared to the lighting in my room. The result was a pitch black image, except when I pointed the camera directly at a light source. Changing the FPS range to a lower one fixed my issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM